INSERT, UPDATE and DELETE
Change the data: add rows, change values in rows, and remove rows.
Syntax
INSERT INTO table_name (columns) VALUES (values);UPDATE table_name SET column = value WHERE condition;DELETE FROM table_name WHERE condition;
Example
UPDATE products SET unit_price = unit_price + 0.10 WHERE category = 'drinks';
Raises the price of each drink by 0.10; other products are untouched.
Tables used: products. Try it in a lesson below.
Common mistakes
- UPDATE and DELETE without WHERE change or remove every row. Run a SELECT with the same WHERE first to check the rows.
- Changes apply straight away in a real database. Practise in a copy, or inside a transaction you can roll back.