Lesson 9 of 10

Changing data

Goal

INSERT, UPDATE and DELETE

01

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.

02

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
  1. Noura from Jeddah was added
  2. Khalid is now in Dammam
  3. The other customers stayed in their cities
  4. No order is below 50
  5. 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');
query.sql
OutputSQLite (sql.js)

Loading SQLite.

–/5

Checks start once the environment is ready.

5 checks listed under “Your task”.