QA
Beginner LevelSQL & MySQL

What is the difference between TRUNCATE and DELETE in SQL?

❓ Interview Prompt: Compare `TRUNCATE TABLE` (DDL, fast drop/recreate, resets auto-increment) vs `DELETE FROM` (DML, row-by-row logging, rollback support).

Comparing table clearing commands:

| Property | 'DELETE FROM table' | 'TRUNCATE TABLE table' |

|---|---|---|

| Command Type | DML (Data Manipulation Language) | DDL (Data Definition Language) |

| Execution | Deletes rows one-by-one with transaction logging | Drops and recreates the underlying table structure |

| Speed | Slower on large datasets | Extremely Fast ($O(1)$ allocation drop) |

| Auto-Increment | Preserves auto-increment counter | Resets auto-increment counter to 1 |

| WHERE Clause | Supported ('WHERE id > 10') | Not Supported (Clears entire table) |

Code Implementation Example

sql
-- Fast table wipe resetting auto-increment counters
TRUNCATE TABLE temp_import_logs;
💡Wiping table contents instantly using TRUNCATE TABLE.
🎯 Interview Key Takeaway

Use TRUNCATE TABLE to empty entire staging tables quickly, and DELETE FROM when filtering specific rows or needing transactional rollbacks.

#SQL#TRUNCATE#DELETE#DDL vs DML#Beginner
Back to all SQL & MySQL Questions→

More SQL & MySQL Interview Questions

Beginner LevelSQL & MySQL

How do B-Tree Indexes work in SQL/MySQL and how do you optimize slow queries using EXPLAIN?

Beginner LevelSQL & MySQL

How do SELECT, WHERE, ORDER BY, and LIMIT clauses filter relational datasets?

Beginner LevelSQL & MySQL

What are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?