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.
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
- What is a transaction, and what do the ACID properties mean?
- What is WAL (write-ahead logging), and how does it support durability and replication?
- What is a deadlock, and how do databases detect and resolve them?
- What is AWS DMS, and when would you use it?
- What is schema migration, and how do you run migrations safely in production?
- What is a composite index, and does column order matter?
- What is connection exhaustion, and how do you prevent it?
- How do you decide which columns to index?