Skip to the workspace
Pebellslearn by building
Data Manipulation Language (DML)  ›  Capstone Project

DELETE — Removing Rows

DELETE 15 minDELETE removes whole rows chosen by WHERE, is blocked by foreign keys that still reference those rows, and is often replaced by a soft delete in real systems.

sql / DELETE — Removing Rows

Explore each scene at your own pace.

01 · The rule

The rule

DELETE — Removing Rows

DELETE removes whole rows chosen by WHERE, is blocked by foreign keys that still reference those rows, and is often replaced by a soft delete in real systems.

Trace deletion through foreign-key rules and compare it with an explicit soft-delete design.

A customer asks for her test orders from last week to be removed. It takes one line of SQL — and a slightly wrong line can remove far more than she asked for. DELETE follows the same pattern as UPDATE, and it deserves the same care.

The rule

DELETE removes whole rows; WHERE decides which — preview it first.

DELETE FROM orders
WHERE status = 'cancelled' AND order_date < '2026-01-01';

DELETE always removes entire rows, and every row that matches the WHERE goes, whether that is one row or a million. There is no column list: you cannot delete "just the email" of a customer. To blank out one value, use UPDATE and set it to NULL instead.

As with UPDATE, leaving out WHERE removes every row in the table. The table itself stays, empty — unlike DROP.

Foreign keys protect related data. If orders references customers, then

DELETE FROM customers WHERE customer_id = 1;

is refused while Asha still has orders, because those orders would point at nobody. You either delete her orders first, or the foreign key was declared with ON DELETE CASCADE, in which case her orders are removed automatically along with her. You will see those options in the constraints section.

Many real systems avoid deleting at all. They add a column such as deleted_at and set it with UPDATE, a pattern called a soft delete. The row stays for history and audits, and queries simply ignore it.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.