TRUNCATE — Remove All Data Quickly
The TRUNCATE statement is used to quickly remove all rows from a table.
It is faster than DELETE because it doesn't log individual row deletions.
TRUNCATE is useful when you want to empty a table completely, but keep the table structure.
Syntax
TRUNCATE TABLE table_name;
Example: Truncate Employees Table
TRUNCATE TABLE employees;
This removes all rows from the employees table, but the table still exists and can be used.
Key Differences: TRUNCATE vs DELETE
| TRUNCATE | DELETE |
|---|---|
| Removes all rows | Can remove some or all rows |
| Faster, less logging | Slower, logs each row deletion |
| Cannot use WHERE clause | Can use WHERE clause |
Tip
TRUNCATEis not reversible- No
WHEREclause, and can’t target specific rows. - Use carefully when you really want to empty a table.
The TRUNCATE statement is a fast and efficient way to clear out a table completely!