INSERT, UPDATE & DELETE
Change data deliberately
Lesson 11 of 20 · 11 min · Module 4: Relationships & real reports
Queries can read records, but applications also create, edit, and remove them. The target and condition of a write deserve careful attention.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Create, update, and remove records
- Target writes with a WHERE clause
- Read back changes to verify their effect
The idea
INSERT INTO adds rows, UPDATE ... SET ... WHERE changes matching rows, and DELETE FROM ... WHERE removes matching rows. This sandbox resets all tables before each run.
UPDATE learners SET xp = 50 WHERE id = 1;
SELECT name, xp FROM learners WHERE id = 1;
01Describe the target precisely
An id identifies the intended row more precisely than a display name that might be duplicated. Before a real write, a SELECT with the same condition can help verify which records match.
02Understand the sandbox boundary
Your writes affect an in-memory example database for this run. They do not modify other learners’ progress. A real application also needs transactions, permissions, backups, and parameterized inputs.
Your turn
(6, 'Taylor', 'Python', 0) into learners. Update Taylor’s XP to 50 using id 6. Delete the enrollments for learner_id 4, then delete the learner with id 4. Finally select name, xp for all remaining learners, sorted by name.What the checks look for
- Adds Taylor, changes only the intended rows, and returns the final result
- Removes dependent enrollments before the learner
Take this with you
Make the target explicit and verify the result of a write.