Modifying Data: INSERT, UPDATE, DELETE
Reading data is only half of SQL. INSERT adds new records, UPDATE changes existing ones, and DELETE removes them. These are the operations that make a database dynamic — every signup, post, purchase, or profile change uses them.
Key Concepts
INSERT INTO
INSERT INTO students (name, grade, gpa) VALUES ('New Student', 10, 3.5) adds a new row. You must provide values for all NOT NULL columns (or all columns if you omit the column list). Auto-increment columns like id are generated automatically.
UPDATE — Changing Data
UPDATE students SET gpa = 3.8 WHERE id = 3 changes the gpa of the student with id=3. ALWAYS include a WHERE clause — without it, you update EVERY row. This is one of the most dangerous mistakes in SQL.
DELETE — Removing Rows
DELETE FROM students WHERE id = 5 removes that student. Again, WHERE is critical — DELETE FROM students with no WHERE deletes the entire table's data. Most production systems use 'soft delete' (set a deleted_at column) instead of truly deleting.
🆕 Data Modification Lab
See INSERT, UPDATE, and DELETE in action. The table updates live!
✅ Check Your Understanding
1. What does INSERT INTO do?
2. Why is WHERE important in an UPDATE statement?
3. What is soft delete?