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

SQL · try it
INSERT INTO products (name, price) VALUES ('Webcam', 59.0);
SELECT * FROM products;

UPDATE changes rows

SQL · try it
UPDATE products SET price = 17.99 WHERE name = 'Mouse';
SELECT name, price FROM products;

DELETE removes rows

SQL · try it
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:

  1. Write the SELECT with your WHERE first and check the rows it returns
  2. Change SELECT * to UPDATE … SET … or DELETE, keeping the same WHERE
  3. On important data, use a transaction so you can undo:
SQL · try it
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 done

Step 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.

SQL
-- INSERT here

SELECT name FROM customers ORDER BY id;

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. What happens if you run UPDATE employees SET salary = 0 without a WHERE?

Create a free account to track your progress.