Menu

1 / 5

DELETE vs TRUNCATE vs DROP: Which One Removes What

DEV Community: backend·Abdeldjalil Chougui·about 6 hours ago
#w4wSfDA1
#devtobackend#devto#dev#table#rows
Long article (934 words) — no AI summary yet.
Reading 0:00
15s threshold

All three commands make data disappear, and all three can ruin your day if you pick the wrong one. The difference is in what they remove and how :

DELETE removes some or all rows , one by one.

TRUNCATE removes all rows at once, keeping the empty table.

DROP removes the table itself : rows, structure, indexes and all.

DELETE FROM sessions WHERE expires_at < now ( ) ; -- some rows TRUNCATE TABLE staging_import ; -- all rows, table stays DROP TABLE old_reports ; -- the table is gone

Enter fullscreen mode

Exit fullscreen mode

Side by side

DELETE TRUNCATE DROP

Removes Rows matching WHERE All rows Table and its data

Table structure Kept Kept Removed

WHERE clause Yes No No

Speed on big tables Slow, row by row Fast Fast

Row triggers fire Yes No No

Rollback Yes, in a transaction PostgreSQL, SQL Server: yes. MySQL, Oracle: no PostgreSQL, SQL Server: yes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.