SQL DELETE Statement

Last updated: August 26, 2026.

DELETE removes rows that match its WHERE condition. Preview the same condition with SELECT and use a transaction when the database supports it.

Delete selected rows

SELECT order_id, status
FROM orders
WHERE status = 'cancelled' AND placed_at < '2025-01-01';

DELETE FROM orders
WHERE status = 'cancelled' AND placed_at < '2025-01-01';

Use a transaction for a controlled change

BEGIN;

DELETE FROM sessions
WHERE expires_at < CURRENT_TIMESTAMP;

-- Check the affected-row count, then:
COMMIT;
-- Or use ROLLBACK instead of COMMIT.

Omitting WHERE deletes every row. Foreign keys may block a delete or cascade it to related tables, so review constraints and take an appropriate backup before large operations.

admin

admin

Leave a Reply

Your email address will not be published.