Comparison · Modifying data

DELETE vs TRUNCATE vs DROP

DELETE removes rows and supports WHERE; TRUNCATE empties the whole table; DROP also removes its definition.

Before continuing: This entry is part of the deleting data guide. If you are new to the topic, start with DELETE.

Examples

What DELETE, TRUNCATE and DROP each affect
StatementAccepts a filter?Keeps the table?Typical use
DELETEYes, with WHEREYesDelete specific rows, or all rows, following the engine's normal delete logic.
TRUNCATE TABLENoYesEmpty a whole table when the engine and dependencies allow it.
DROP TABLENoNoRemove the table, its data and the objects tied to its definition.
Alternatives; do not run them in sequence
DELETE FROM orders WHERE status = 'cancelled';
-- Both operations affect the entire table:
TRUNCATE TABLE orders;
DROP TABLE orders;

Differences and trade-offs

Safe routine before deleting

  1. Write a SELECT with the same condition and review the rows.
  2. Check the foreign keys, views, processes and permissions that depend on the table.
  3. Decide whether you need to keep the structure, the unselected data and the identifiers.
  4. Use a transaction when the engine and the specific statement allow it to be rolled back.
  5. Check the result before committing, and keep a separate recovery plan.
DELETE routine
SELECT id, status, total
FROM orders
WHERE status = 'cancelled';

BEGIN;
DELETE FROM orders
WHERE status = 'cancelled';

SELECT COUNT(*) AS remaining_cancelled
FROM orders
WHERE status = 'cancelled';
ROLLBACK;

The example ends with ROLLBACK so you can practise without keeping the delete. In production, check the transaction syntax and restrictions of your engine.

Differences you should not generalise

How TRUNCATE and data definition statements behave varies between engines. Rollback support, identity column handling, trigger execution, permissions and foreign key handling can all differ.

  • PostgreSQL: documents TRUNCATE as an operation that removes every row without scanning them one by one and that can take part in a transaction.
  • SQL Server: keeps the structure, normally resets the identity counter and can be rolled back inside a transaction, with documented limitations.
  • MySQL: treats TRUNCATE TABLE as a data definition statement with its own rules; do not assume it behaves like a transactional DELETE.
  • SQLite: has no TRUNCATE TABLE; a DELETE without a filter can use an internal optimisation.