Lesson 9 of 10
Changing data
- 14 min
- 5 checks
- 3 hints
- Go to task
Goal
INSERT, UPDATE and DELETE
Explanation
Three statements change data instead of reading it: INSERT INTO adds rows, UPDATE ... SET changes values, and DELETE FROM removes rows.
UPDATE and DELETE act on every row that matches WHERE, so if you leave out WHERE, the change or the deletion hits every row in the table. On its own, UPDATE customers SET city = 'Dammam' moves all of your customers to Dammam. It won't ask you to confirm, and you can't undo it.
The safe habit is to try the condition with SELECT * first, make sure it returns only the rows you mean, and only then change the start of the statement to UPDATE or DELETE.
Your task
Add the customer 'Noura' from 'Jeddah', move 'Khalid' to 'Dammam', and delete every order whose total is less than 50.
Checks
5 checks- Noura from Jeddah was added
- Khalid is now in Dammam
- The other customers stayed in their cities
- No order is below 50
- The other orders weren't deleted
Tables in this lesson
CREATE TABLE customers ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, city TEXT NOT NULL ); CREATE TABLE orders ( id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(id), total INTEGER NOT NULL, placed_on TEXT NOT NULL ); INSERT INTO customers (id, name, city) VALUES (1, 'Layan', 'Riyadh'), (2, 'Khalid', 'Jeddah'), (3, 'Reem', 'Dammam'), (4, 'Fahd', 'Riyadh'); INSERT INTO orders (customer_id, total, placed_on) VALUES (1, 120, '2026-09-01'), (1, 80, '2026-09-12'), (2, 300, '2026-09-03'), (3, 45, '2026-09-20'), (2, 60, '2026-09-25');