← Learning Hub
Beginner

INSERT, UPDATE and DELETE

SQL can also change data. In Try it, the database resets every Run, so experiment freely.

Reading data is half the story; apps also add, change and remove it. These three commands change data permanently, so care matters: an UPDATE or DELETE without a WHERE affects every row in the table. Professionals test the WHERE with a SELECT first.

INSERT - add rows

Example
INSERT INTO customers (id, name, city, joined)
VALUES (7, 'Kiran Das', 'Kolkata', '2026-11-20');

SELECT * FROM customers WHERE id = 7;

-- Result:
-- id | name      | city    | joined
-- ---+-----------+---------+-----------
-- 7  | Kiran Das | Kolkata | 2026-11-20
▶ Try it yourself

UPDATE - change rows

Example
UPDATE products
SET price = price - 100
WHERE category = 'Books';

SELECT name, price FROM products WHERE category = 'Books';

-- Result:
-- name          | price
-- --------------+------
-- Notebook Pack | 99
-- Python Book   | 499
▶ Try it yourself

DELETE - remove rows

Example
DELETE FROM orders WHERE status = 'cancelled';

SELECT COUNT(*) AS orders_left FROM orders;

-- Result:
-- orders_left
-- -----------
-- 7
▶ Try it yourself
Always write the WHERE first. UPDATE products SET price = 0; or DELETE FROM orders; without a WHERE changes every row. On a real database, run the same WHERE as a SELECT first to see which rows will change.
Key points
  • INSERT adds rows; UPDATE changes them; DELETE removes them.
  • Always use WHERE with UPDATE and DELETE.
  • Check with a SELECT before changing data.

📝 Test yourself

1. What happens with DELETE FROM orders; (no WHERE)?
2. Which statement changes existing rows?
3. Fill in the keyword that sets new values:
UPDATE products stock = 0 WHERE id = 4;