Preview, then delete
DELETE ... WHERE, and what remains
Old orders to clear out, with a boundary date that is easy to get wrong by one day.
Can you
- Delete exactly the rows the preview showed
- Prove what remains with a count and the earliest surviving row
- Explain why a referenced parent row refuses to go
The reading
Read the whole chapterPreview, then delete
SELECT COUNT(*) AS orders_left, MIN(order_date) AS earliest
FROM orders;DELETE FROM orders WHERE order_date < '2026-01-20' removes whole rows, 71 of them. The same two rules apply: preview with the same WHERE first, and read what remains. 204 orders minus 71 is 133, and SELECT COUNT(*), MIN(order_date) FROM orders afterwards should say 133 and 2026-01-20. If it says 122, your boundary ate the 20th.
DELETE with no WHERE empties the table, row by row, with no undo in the browser and no undo on the desktop either, unless you were inside a transaction. The disposable copy means you can try it once to see what 'no rows' looks like.
Rule of thumb. Preview the rows, delete them, then count and inspect what remains.
Going deeper (optional, not on the exam)
With foreign keys on, a parent row with children refuses to go: DELETE FROM employees WHERE id = 24 fails with FOREIGN KEY constraint failed, because seven orders point at that employee. The database is protecting the orders. What to do about them is a design decision, which chapter 6 and Lab 10 cover.
The ladder
Start at the first rung even if the idea looks familiar: it is answerable from the reading alone, and the climb is where the difficulty lives. A wrong answer sends you back to the paragraph that teaches it, then to a hint, then to the worked answer.
Learn
- Practise this rung
Level 1: Watch it answered
- Practise this rung
Level 2: Fill the blank
Practise
- Practise this rung
Level 3: Predict the result
- Practise this rung
Level 4: Write it yourself
Master
- Practise this rung
Level 5: Repair it
- Practise this rung
Level 6: Transfer it
Keep practising
The whole bank for this concept, in any order, with the same review, hint and worked answer.
Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.