Removing rows with DELETE
Delete exactly the rows you mean.
DELETE FROM table WHERE condition; removes the rows that match. As with UPDATE, the WHERE is your safety belt: DELETE FROM orders; with no WHERE empties the whole table. Before deleting, run a SELECT with the same WHERE and look at the rows that would disappear.
DELETE FROM orders
WHERE status = 'cancelled';Removes only cancelled orders. Every other order stays.
Remember how NULL works: DELETE FROM loans WHERE returned_date < '2024-09-01' does not remove loans that are still out, because comparing NULL is never true.
Real systems keep backups, and many teams mark rows as inactive instead of deleting them, so mistakes can be undone.