Lesson 8 of 10 · 9 min · 3 hands-on steps
INSERT, UPDATE & DELETE
Add, change and remove data safely, and why WHERE is your seatbelt.
INSERT adds rows
INSERT INTO products (name, price) VALUES ('Webcam', 59.0);
SELECT * FROM products;UPDATE changes rows
UPDATE products SET price = 17.99 WHERE name = 'Mouse'; SELECT name, price FROM products;
DELETE removes rows
DELETE FROM orders WHERE ordered_on < '2026-02-01'; SELECT * FROM orders;
⚠️ WHERE is your seatbelt
UPDATE or DELETE without WHERE affects every row, instantly, with no undo. This mistake has taken down real companies' data.
The professional habit:
- Write the
SELECTwith yourWHEREfirst and check the rows it returns - Change
SELECT *toUPDATE … SET …orDELETE, keeping the sameWHERE - On important data, use a transaction so you can undo:
BEGIN; DELETE FROM customers WHERE city = 'Lagos'; SELECT COUNT(*) AS left_after_delete FROM customers; ROLLBACK; -- changed our mind: nothing was really deleted
(Each run here starts from a fresh practice database, so experiment freely.)
🧪 Practice: 3 steps
0 / 3 doneStep 1 of 3 · A new customer
Add a customer named Fatima from Nairobi (let the database pick the id), then select all customer names ordered by id to check it worked.
-- INSERT here SELECT name FROM customers ORDER BY id;
Output appears here. Press Run or Ctrl/⌘ + Enter.
Step 2 of 3 · A raise for Design
Give everyone in Design (department_id = 2) a 10% raise, then select name, salary for that department ordered by name.
-- UPDATE here SELECT name, salary FROM employees WHERE department_id = 2 ORDER BY name;
Output appears here. Press Run or Ctrl/⌘ + Enter.
Step 3 of 3 · Remove small orders
Delete every order with a quantity of 1, then select the remaining order ids in order.
SELECT id FROM orders ORDER BY id;
Output appears here. Press Run or Ctrl/⌘ + Enter.
✅ Check your understanding
What happens if you run UPDATE employees SET salary = 0 without a WHERE?
Create a free account to track your progress.