Inserting, Updating and Deleting
💻 SQLChange data safely with INSERT, UPDATE and DELETE, and always scope changes with WHERE.
Reading data is safe. Changing it is not. Every write statement deserves a test query first.
- Insert one or many rows.
- Update specific rows.
- Delete safely.
INSERT
List the columns explicitly so the statement keeps working if the table gains a column.
INSERT INTO students (name, level, email)
VALUES ('Amina Bello', 'SS2', 'amina@example.com');
INSERT INTO students (name, level)
VALUES
('Bola Ade', 'SS1'),
('Chidi Okeke', 'SS3');UPDATE
Always include a WHERE clause. Run the same condition as a SELECT first to see which rows you are about to change.
-- Check first
SELECT id, name, score FROM students WHERE level = 'SS1';
-- Then update
UPDATE students
SET score = score + 5
WHERE level = 'SS1';DELETE
Delete with a precise condition. To remove every row on purpose, use TRUNCATE, which is faster and resets auto-increment.
DELETE FROM students
WHERE id = 12;Practice
- Insert three new courses in one statement.
- Increase the price of one course by 10%.
- Delete students who have no email and are inactive.
Hands-on exercise
Write two statements:
1. A SELECT that shows courses priced below 5000.
2. An UPDATE that raises those prices by 10%.
The UPDATE must not touch any other course.
Recap
INSERT adds rows, UPDATE changes them and DELETE removes them. Always preview with SELECT and keep the WHERE clause precise.
Example
INSERT INTO students (name, level, email)
VALUES ('Amina Bello', 'SS2', 'amina@example.com');
INSERT INTO students (name, level)
VALUES
('Bola Ade', 'SS1'),
('Chidi Okeke', 'SS3');
Exercises
1. A SELECT that shows courses priced below 5000.
2. An UPDATE that raises those prices by 10%.
The UPDATE must not touch any other course.
Expected Output
Only courses below 5000 are increased, by exactly 10%.
Lesson Nav
SQL Course
0/9 lessons completed
- 1 What a Database Is Tutorial
- 2 Filtering and Sorting Tutorial
- 3 Aggregates and Grouping Tutorial
- 4 Joining Tables Tutorial
- 5 Subqueries and Common Table Expressions Tutorial
- 6 Inserting, Updating and Deleting Tutorial
- 7 Schemas, Keys and Normalisation Tutorial
- 8 Indexes and Query Performance Tutorial
- 9 Project: A Reporting Query Project