DELETE vs TRUNCATE vs DROP
Know exactly what DELETE, TRUNCATE and DROP remove, how they differ, and which one to use.
"Remove the data" can mean three very different things: delete some rows, empty the whole table quickly, or destroy the table. Mixing these up is one of the most expensive beginner mistakes — and one of the most common interview questions.
Definitions
DELETE (DML) removes rows from a table — some rows (with WHERE) or all rows — one row at a time, logging each deletion. The table remains.
TRUNCATE TABLE removes all rows from a table at once by releasing the data pages, which is much faster than DELETE. It cannot use WHERE. The table structure remains. (SQL Server classifies it as a DDL statement.)
DROP TABLE (DDL) removes the whole table — structure and data. The table no longer exists.
Syntax
sql
DELETE FROM players WHERE id = 6; -- some rows
DELETE FROM players; -- all rows, slowly
TRUNCATE TABLE players; -- all rows, fast (SQL Server)
DROP TABLE players; -- the whole tableDELETE vs DROP — do not mix them up!
DELETE FROM players | DROP TABLE players |
|---|---|
| DML | DDL |
| Removes ROWS (data) | Removes the WHOLE table |
| The table stays, structure stays | Structure AND data are gone |
| Result: an empty table — but it still exists | Result: players doesn't exist |
The full comparison
| Feature | DELETE | TRUNCATE | DROP |
|---|---|---|---|
| Command type | DML | DDL (in SQL Server) | DDL |
| Removes | Selected rows or all rows | All rows | Table + all rows |
WHERE allowed? | ✅ Yes | ❌ No | ❌ No |
| Table still exists? | ✅ Yes | ✅ Yes | ❌ No |
| Speed on big tables | Slow (row by row, fully logged) | Very fast (minimally logged) | Very fast |
Resets IDENTITY counter? | ❌ No — next id continues | ✅ Yes — back to the seed | (table gone) |
| Fires DELETE triggers? | ✅ Yes | ❌ No | ❌ No |
| Works if a FOREIGN KEY references the table? | ✅ Yes (if no child rows block it) | ❌ No | ❌ No |
| Rollback in a transaction (SQL Server)? | ✅ Yes | ✅ Yes | ✅ Yes |
| Permission needed | DELETE | ALTER | ALTER / CONTROL |
Note: A common myth is "TRUNCATE can't be rolled back". In SQL Server it can, when run inside an explicit
BEGIN TRANSACTION. In MySQL and Oracle, TRUNCATE auto-commits and can't be rolled back.
Example — the same table, three ways
Start: players has 6 rows.
| Statement | Rows afterwards | Can you still SELECT * FROM players? |
|---|---|---|
DELETE FROM players WHERE runs < 400; | 4 (Dhoni & Bumrah gone) | ✅ Yes |
DELETE FROM players; | 0 | ✅ Yes — empty result |
TRUNCATE TABLE players; | 0 | ✅ Yes — empty result |
DROP TABLE players; | — | ❌ Invalid object name 'players' |
IDENTITY after DELETE vs TRUNCATE (SQL Server)
sql
-- fans has fan_id INT IDENTITY(1,1) and 3 rows (ids 1, 2, 3)
DELETE FROM fans;
INSERT INTO fans (name) VALUES ('Ravi'); -- gets fan_id = 4 (counter continues)
TRUNCATE TABLE fans;
INSERT INTO fans (name) VALUES ('Ravi'); -- gets fan_id = 1 (counter reset)Which one should I use?
| You want to… | Use |
|---|---|
| Remove some rows | DELETE … WHERE |
| Empty a table but keep it (small table, or triggers/FKs involved) | DELETE |
| Empty a big staging table quickly and reset ids | TRUNCATE TABLE |
| Get rid of the table completely | DROP TABLE |
Common mistakes
- ❌
TRUNCATE TABLE players WHERE id = 6→ syntax error. ✅ TRUNCATE has no WHERE — use DELETE. - ❌
DROPwhen you meant to empty the table → the structure is gone too. ✅DELETE/TRUNCATE. - ❌
TRUNCATEon a table referenced by a foreign key → error. ✅ UseDELETE, or drop the foreign key first. - ❌ Saying "DELETE is DDL". ✅ DELETE is DML; DROP is DDL.
SQL Server vs MySQL / PostgreSQL / SQLite
TRUNCATE TABLE exists in SQL Server, MySQL and PostgreSQL. SQLite has no TRUNCATE — DELETE FROM table without WHERE is automatically optimised instead. That's why the playground examples use DELETE.
Interview tip
Q: Difference between DELETE, TRUNCATE and DROP? A: DELETE is DML and removes selected (or all) rows one by one, supports WHERE, fires triggers and keeps the identity counter. TRUNCATE removes all rows at once, is much faster, has no WHERE, resets the identity and is blocked by foreign keys. DROP removes the whole table — structure and data. In SQL Server all three can be rolled back inside an explicit transaction.
Key points to remember
- DELETE (DML) removes some or all rows, supports WHERE, and keeps the table.
- TRUNCATE TABLE removes ALL rows at once, very fast, no WHERE, and keeps the table.
- DROP TABLE (DDL) removes the table completely — structure and data.
- TRUNCATE resets an IDENTITY counter; DELETE does not.
- TRUNCATE doesn't fire DELETE triggers and can't run on a table referenced by a foreign key.
- In SQL Server, DELETE, TRUNCATE and DROP can all be rolled back inside an explicit transaction.
- SQLite (the playground) has no TRUNCATE — DELETE FROM table does the same job there.
Try it yourself
SQL Server: TRUNCATE TABLE
-- Removes ALL rows at once; the table stays
TRUNCATE TABLE players;
SELECT COUNT(*) AS players_left FROM players; -- 0
-- ❌ Not allowed: TRUNCATE has no WHERE
-- TRUNCATE TABLE players WHERE id = 6;SQL Server-specific — run this in SQL Server (SSMS / Azure Data Studio).
DELETE some rows vs DELETE all rows
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
DELETE keeps the table, DROP removes it
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: choose the right command
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
