Interview Databases & Caching

What is the difference between DELETE, TRUNCATE, and DROP?

Databases & Caching · Intermediate level

Answer

DELETE removes selected rows, usually with a WHERE clause. TRUNCATE removes all rows from a table more quickly but with stronger table-level implications. DROP removes the table object and its definition entirely.

Technical explanation

DELETE is selective and can be batched, but huge deletes create logs, bloat, locks, and replica lag.

TRUNCATE is fast for emptying a table but usually takes stronger locks and affects the whole table.

DROP removes schema and data, so it requires backups, approvals, and migration controls.

Hands-on example

Safe batch delete:

DELETE FROM events WHERE id IN (SELECT id FROM events WHERE created_at < now() - interval '180 days' LIMIT 10000);

Repeat with sleeps and monitor locks, WAL, replica lag, and table bloat.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Databases & Caching interview questions

← All Databases & Caching questions