Students change rows with UPDATE and remove rows with DELETE, and learn that WHERE decides which rows.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 7 min · Modify and Make 10 min
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Pairs write a DELETE for a rule (songs older than 2018). They write the matching SELECT first and agree on the rows before they change the word.
Remembering WHERE. Teach the habit: write it as a SELECT first, then change the first word.
| What you will see | A question to ask | The fix |
|---|---|---|
| Every row changed. | Does your query have a WHERE line? | Press Reset, add the WHERE line, and run again. |
| Nothing changed. | Does any row pass your WHERE test? | Check the id or spelling against the table. |
| syntax error near DELETE | Is FROM in the DELETE line? | It is DELETE FROM table. |
One possible solution for each task. Other correct programs are fine.
UPDATE songs
SET year = 2018
WHERE id = 6;
SELECT title, year FROM songs WHERE id = 6;
DELETE FROM songs
WHERE plays < 2000;
SELECT title FROM songs;
Stretch: Raise the plays of every pop song by 10% with plays * 1.1, then look at the results.
Support: Give the UPDATE with the WHERE line missing and ask students to complete it.
What happens if you write DELETE FROM songs; with no WHERE?
Every row in the table is removed. WHERE chooses which rows.
Next lesson: designing a table, with keys that make each row unique.