DELETE, TRUNCATE, and DROP in SQL: The Difference Interviewers Test
DELETE removes chosen rows, TRUNCATE empties the table but keeps its structure, and DROP removes the table itself. But the rollback answer changes with the database, and a confident yes or no will be wrong for at least one popular database.
Say you are in a campus placement interview, and the panel asks, "What is the difference between DELETE, TRUNCATE and DROP?" You give the answer most notes teach: DELETE removes rows, TRUNCATE removes all rows, DROP removes the table. The interviewer nods and asks one more thing. "Can TRUNCATE be rolled back?"
That follow-up is where most freshers lose the point. The correct answer is no in MySQL and yes in PostgreSQL and SQL Server, so a confident yes or no will be wrong for at least one popular database.
DELETE removes chosen rows, TRUNCATE empties the whole table but keeps its structure, and DROP removes the table itself. DELETE is logged row by row and can be rolled back. TRUNCATE is much faster and resets auto-increment, and it rolls back in PostgreSQL and SQL Server but not in MySQL, as the SQLNoir guide shows. DROP needs a backup to undo. The sections below run all three on the same small table.
Each command side by side, compared in one table
One table shows what each command removes, whether it takes WHERE, its SQL type (DML or DDL), whether it fires triggers, and whether it resets auto-increment. The rows follow the GeeksforGeeks comparison of the three commands.
DML means data manipulation language: commands that change the data inside a table. DDL means data definition language: commands that change the table as an object.
| DELETE | TRUNCATE | DROP | |
|---|---|---|---|
| What it removes | Rows you choose | All rows | The whole table |
| WHERE clause | Yes | No | No |
| Command type | DML | DDL | DDL |
| Fires triggers | Yes, per row | No | No |
| Resets auto-increment | No | Yes | Counter is gone with the table |
| Rollback | Yes | Depends on the database | Needs a backup once committed |
| Speed on a big table | Slowest | Fast | Fast |
If you can redraw this table on paper, you can rebuild every answer from it.
SQL questions like this one also show up in data roles. If that is your track, the machine learning and data science interview questions post covers the rest of that round.
DELETE removes rows you choose
DELETE is the only one of the three that accepts a WHERE clause, so it can remove one row or all of them while the table stays (see the GeeksforGeeks breakdown). That makes the delete query in SQL a DML command, in the same family as INSERT and UPDATE.
-- remove only the HR staff
DELETE FROM employees WHERE department = 'HR';
-- remove every row, keep the table
DELETE FROM employees;
The database writes each removed row to its transaction log, one at a time. That log is what lets you roll back. It is also why DELETE gets slow when the table holds a lot of data.
Triggers fire for every row DELETE removes. If your team keeps an audit trigger that copies deleted rows into a history table, it keeps working with DELETE.
The auto-increment counter is left alone. The worked example further down shows what that means for the next insert.
TRUNCATE empties the table but keeps its shape
TRUNCATE takes no WHERE, skips row-by-row logging and trigger firing, and starts the auto-increment counter again, as the SQLNoir visual guide lays out. Because it acts on the table as a whole, SQL classes it as DDL, next to CREATE and DROP.
TRUNCATE TABLE employees;
Instead of removing rows one by one, TRUNCATE deallocates the data pages, the blocks of storage the rows live in. On tables with millions of rows, SQLNoir reports TRUNCATE running far faster than DELETE, though the gap depends on table size and database.
John Deardurff's SQL Server walkthrough shows this at the storage level. After DELETE, the emptied pages stay with the table, ready for new rows. After TRUNCATE, the pages themselves are released.
The columns, indexes and constraints all survive. You can insert into the table straight away.
DROP removes the table itself
DROP deletes the data, the structure, the indexes and the constraints, and you cannot get them back without a backup, as the GeeksforGeeks DROP and TRUNCATE page explains.
DROP TABLE employees;
-- safer in scripts you run more than once
DROP TABLE IF EXISTS employees;
An empty table and a missing table are different problems. To use the name again after DROP, you must rewrite the CREATE TABLE statement, every index and every constraint. Any view or stored procedure that read from the table also stops working.
IF EXISTS tells the database to skip quietly when the table is not there. Without it, a setup script stops with an error the second time you run it. Make it a habit in practice scripts.
One employees table before and after each command
Running each command on the same five-row employees table shows the three results: some rows gone, zero rows, or no table. Here is the setup in MySQL, with made-up sample names.
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
department VARCHAR(20)
);
INSERT INTO employees (name, department) VALUES
('Asha', 'HR'), ('Rohan', 'Sales'), ('Meera', 'HR'),
('Vikram', 'IT'), ('Priya', 'IT');
Before any command, the table looks like this:
| id | name | department |
|---|---|---|
| 1 | Asha | HR |
| 2 | Rohan | Sales |
| 3 | Meera | HR |
| 4 | Vikram | IT |
| 5 | Priya | IT |
After DELETE with WHERE
DELETE FROM employees WHERE department = 'HR';
INSERT INTO employees (name, department) VALUES ('Kabir', 'HR');
SELECT * FROM employees;
-- 2 Rohan Sales
-- 4 Vikram IT
-- 5 Priya IT
-- 6 Kabir HR
Kabir gets id six, not one and not three. The counter remembers the highest id it ever handed out, and the gaps left by Asha and Meera stay empty.
After TRUNCATE
TRUNCATE TABLE employees;
INSERT INTO employees (name, department) VALUES ('Kabir', 'HR');
SELECT * FROM employees;
-- 1 Kabir HR
Here Kabir gets id one. The table behaves as if it had just been created.
After DROP
DROP TABLE employees;
SELECT * FROM employees;
-- ERROR 1146 (42S02): Table 'practice.employees' doesn't exist
The SELECT itself fails, which is the clearest sign that nothing is left to query.
| Command | Rows left | Next id | Table exists? |
|---|---|---|---|
| DELETE WHERE department = 'HR' | three | six | Yes |
| TRUNCATE | none | one | Yes |
| DROP | none | no counter | No |
Can TRUNCATE be rolled back? It depends on the database
TRUNCATE rolls back inside an explicit transaction in PostgreSQL and SQL Server, but not in MySQL, where it commits at once, according to the database-specific table in the SQLNoir guide.
| Database | Can TRUNCATE be rolled back? | What to remember |
|---|---|---|
| MySQL | No | TRUNCATE causes an implicit COMMIT |
| PostgreSQL | Yes, inside an explicit transaction | Start with BEGIN |
| SQL Server | Yes, inside an explicit transaction | Start with BEGIN TRANSACTION |
An "explicit transaction" means you open it yourself before the command runs. Without one, most tools commit each statement on its own, and there is nothing left to roll back.
-- SQL Server
BEGIN TRANSACTION;
TRUNCATE TABLE employees;
SELECT COUNT(*) FROM employees; -- 0
ROLLBACK;
SELECT COUNT(*) FROM employees; -- the rows are back
Try the same idea in MySQL with START TRANSACTION. The last count stays at zero, because TRUNCATE committed before ROLLBACK ever ran.
The reason is the command type. MySQL treats TRUNCATE as DDL, and a DDL statement there causes an implicit commit, so the change is saved the moment it runs. PostgreSQL and SQL Server keep TRUNCATE inside the open transaction, which is why it can be undone there. The SQLNoir guide lists the behaviour for each database.
You do not know which database the interviewer uses, so name each one. A per-database answer is safe with both of them: "In MySQL, no, because it commits implicitly. In PostgreSQL and SQL Server, yes, if I run it inside an explicit transaction."
Which command to use for which job
Use DELETE when you need a filter or a safe undo. Use TRUNCATE to reset a table you own, and DROP only when the table should no longer exist. Here are the TRUNCATE pros and cons compared with DELETE:
TRUNCATE: pros
- Clears a large staging or test table in moments.
- Gives you a clean id counter for repeatable test data.
- Leaves the transaction log much smaller.
Cons
- Cannot keep some rows and remove others.
- Audit triggers never see the removed rows.
- Blocked by foreign keys from other tables.
The decision comes down to two questions. Do you need only some rows gone, or a guaranteed way back? Pick DELETE. Is the whole table yours to empty, with nothing pointing at it? Pick TRUNCATE.
Common mistakes
- DELETE with no WHERE. On a shared database, this wipes data other people need. Run the SELECT version first.
- TRUNCATE on a table with foreign keys. The command errors out mid-script. Check for references before you write it.
- Trusting rollback in MySQL. See the rollback section.
- DROP when you meant TRUNCATE. You wanted an empty table and now you must rebuild its structure from scratch. Read the command once more before pressing Enter.
How do you answer this in the interview?
Give the table in three sentences, then volunteer the rollback difference by database before the interviewer asks. Order matters here. This order works because it covers the follow-up before it comes, as the walkthrough on SQLMCT frames it: scope first, storage second.
Scope
Say what each command removes and name DML versus DDL.
Speed and logging
Explain that TRUNCATE frees data pages instead of logging each row.
Auto-increment
Mention which command restarts the id counter, using the employees example.
Rollback by database
Give the MySQL answer and the PostgreSQL or SQL Server answer separately.
Before the interview, read the GeeksforGeeks DROP and TRUNCATE page once. Then see how a full technical round runs in this Infosys SP and DSE interview experience.
Open a free SQL practice tool today, such as DB Fiddle, and create the five-row employees table. Run each command in turn on MySQL. Then run the START TRANSACTION and ROLLBACK test on TRUNCATE and see the count stay at zero. Tomorrow, redraw the comparison table and the before-and-after employees table from memory on paper.
