MyMisPal
← SQL lessons
Lesson 11 of 12

INSERT, UPDATE and DELETE

INSERT adds a row. Always list the column names so the order cannot get mixed up:

SQL
INSERT INTO customers (customer_id, name, city, country, signup_date)
VALUES (11, 'Taif Roses Co', 'Taif', 'Saudi Arabia', '2024-09-01');

SELECT * FROM customers WHERE customer_id = 11;

UPDATE changes existing values. DELETE removes rows.

SQL
UPDATE products
SET stock = stock - 5
WHERE product_id = 1;

SELECT name, stock FROM products WHERE product_id = 1;
Watch outThe most important tip in SQL: never write UPDATE or DELETE without WHERE. Without it, the change hits every row. Run a SELECT with the same condition first.

The editor here is safe: undo any change with the “Reset data” button.

Exercises

Exercise 1

Add department 7 named Legal in Riyadh.

Exercise 2

Raise salaries in the IT department (dept_id 2) by 10%.

Exercise 3

Delete every order whose status is Cancelled.

Spotted a mistake on this page, or have an idea to improve the site?