Data Manipulation Flashcards
What is data manipulation in SQL?
Commands used to manipulate the actual data inside tables (CRUD operations).
What does CRUD stand for?
Create, Read, Update, Delete.
What is the syntax to insert records into a table?
INSERT INTO table_name (column1, column2, …) VALUES (value1, value2, …);
What happens if you don’t mention a column in the INSERT statement?
The column will take the NULL value by default.
Why should the order of values in INSERT match the order of columns?
Because the column/value matching is positional.
What does INSERT INTO allow you to do?
Add new records into a table.
Can you insert multiple records at once with INSERT INTO?
Yes, by separating values with commas.
What is the syntax to update values in a table?
UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition;
What happens if you omit the WHERE clause in an UPDATE command?
All records in the table will be updated.
Why is the WHERE clause important in an UPDATE command?
To target specific records and avoid unintended updates.
Give an example of updating an employee’s salary.
UPDATE employees SET salary = 60000 WHERE employee_id = 1;
What is the syntax to delete records from a table?
DELETE FROM table_name WHERE condition;
What happens if you omit the WHERE clause in a DELETE command?
All records in the table will be deleted.
Why is the WHERE clause critical in a DELETE command?
To prevent accidental deletion of all data.
If you want to remove only employees in the ‘Sales’ department, how would you do it?
DELETE FROM employees WHERE department = ‘Sales’;
If you want to give all employees a 10% raise, what should you use?
UPDATE employees SET salary = salary * 1.10;
How would you insert a new customer record with specific values?
INSERT INTO customers (name, email) VALUES (‘John Doe’, ‘john@example.com’);
Spot the mistake: ‘INSERT table_name (column1, column2) VALUES (value1, value2);’
Correct syntax is: INSERT INTO table_name (column1, column2) VALUES (value1, value2);
Spot the mistake: ‘UPDATE SET column1 = value1 WHERE condition;’
Missing table name. Correct syntax is: UPDATE table_name SET column1 = value1 WHERE condition;
Spot the mistake: ‘DELETE table_name WHERE condition;’
Correct syntax is: DELETE FROM table_name WHERE condition;
Which SQL command adds new records to a table?
INSERT INTO.
Which SQL command updates existing records?
UPDATE.
Which SQL command removes records from a table?
DELETE.
Explain why the WHERE clause is crucial in UPDATE and DELETE operations.
To ensure only the intended records are modified or deleted, preventing accidental changes to the whole table.
Describe what happens if you forget to include WHERE in an UPDATE command.
All records in the table will be updated, which may cause data loss.
If you accidentally run DELETE without WHERE, what is the consequence?
All records in the table will be deleted.
Why is INSERT considered part of CRUD operations?
Because it creates new records in the database.