Learn with Abdou

Chapter 9 · Concept 4 of 6

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

Preview, then delete

SELECT COUNT(*) AS orders_left, MIN(order_date) AS earliest
FROM orders;
The question to ask after the delete: how many are left, and where does the data now start? Open in the playground

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

Six rungs

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

  1. Level 1: Watch it answered

    1 exercise · Not yet

    Practise this rung
  2. Level 2: Fill the blank

    1 exercise · Not yet

    Practise this rung

Practise

  1. Level 3: Predict the result

    1 exercise · Not yet

    Practise this rung
  2. Level 4: Write it yourself

    1 exercise · Not yet

    Practise this rung

Master

  1. Level 5: Repair it

    1 exercise · Not yet

    Practise this rung
  2. Level 6: Transfer it

    1 exercise · Not yet

    Practise this rung

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.