(because sometimes you just want a fresh start)
Quick Syntax
TRUNCATE TABLE table_name;
You’re telling SQL:
“Clear out all the rows — but keep the table structure.”
No data left, but the columns, types, and table still exist.
Imagine your table looks like this:
id | name | age | phone |
---|---|---|---|
1 | Olivia | 26 | 5550001234 |
2 | Mason | 24 | 5556712345 |
3 | Zoe | 30 | 5559083344 |
4 | Ethan | 21 | 5554421199 |
5 | Harper | 25 | 5552223344 |
Now you want to clear all the data but keep the table setup.
Maybe you’re starting a new batch of records or cleaning test data.
TRUNCATE the table
TRUNCATE TABLE friends;
Output:
Query OK, 0 rows affected
What’s left after?
SELECT * FROM friends;
Output:
id | name | age | phone |
---|---|---|---|
empty table |
The table is still there, still has all the same columns — but now it’s empty. Fresh as new.
TRUNCATE vs DELETE
Feature | DELETE | TRUNCATE |
---|---|---|
Deletes rows | Yes | Yes |
Keeps structure | Yes | Yes |
Slower | Can be slow | Fast (no logging) |
Can use WHERE | Yes | No — all rows only |
Auto-increment ID | Continues count | Often resets to 1 |
Recap
TRUNCATE
clears all rows but keeps the table- Super fast and clean — but removes everything
- You can’t filter — it’s all or nothing
- Great for resetting test data or starting fresh
Want to know more about what kinds of data you can store in your tables? You can read more here:
More about SQL data types