Data Manipulation Flashcards
(25 cards)
What is data manipulation in SQL?
Using commands to insert, update, or delete data inside tables — the CRUD operations.
What does CRUD stand for?
Create, Read, Update, Delete.
What command is used to insert data into a table?
INSERT INTO table_name (columns) VALUES (values);
What happens to columns not listed in the INSERT?
They receive NULL by default unless a DEFAULT value is defined.
Why must the values in INSERT match the column order?
Because the values are assigned by position, not by name.
How can you insert multiple rows at once?
List multiple sets of values, separated by commas.
What is the syntax for updating table values?
UPDATE table_name SET column1 = value1, … WHERE condition;
What happens if you omit the WHERE clause in UPDATE?
All rows in the table are updated.
Why is WHERE clause important in UPDATE?
To restrict changes only to relevant rows.
What is the syntax to delete rows from a table?
DELETE FROM table_name WHERE condition;
What happens if you omit WHERE in DELETE?
All rows in the table will be deleted.
Why is the WHERE clause critical in DELETE?
To prevent accidental deletion of all data.
If you want to delete all employees from ‘Sales’, what command would you use?
DELETE FROM employees WHERE department = ‘Sales’;
If you want to increase all salaries by 10%, what command would you use?
UPDATE employees SET salary = salary * 1.10;
How would you insert a new student with name and email?
INSERT INTO students (name, email) VALUES (‘Alice’, ‘alice@example.com’);
Spot the mistake: ‘INSERT table_name (col1) VALUES (val1);’
Missing INTO — should be INSERT INTO table_name …
Spot the mistake: ‘UPDATE SET name = ‘Tom’ WHERE id = 2;’
Missing table name after UPDATE.
Spot the mistake: ‘DELETE users WHERE age < 18;’
Missing FROM — should be DELETE FROM users …
Which SQL command is used to add new data?
INSERT.
Which SQL command updates existing data?
UPDATE.
Which SQL command removes data from a table?
DELETE.
Explain why WHERE is crucial in UPDATE/DELETE operations.
Without WHERE, the operation affects every row — which can cause catastrophic data loss.
Describe the role of INSERT in data manipulation.
It creates new rows in the specified table.
If you run DELETE without a WHERE clause by mistake, what’s the result?
All records are permanently deleted from the table.