TRUNCATE TABLE
Descriptionβ
This statement is used to truncate the specified table and partition data.
Syntax:
TRUNCATE TABLE [db.]tbl[ PARTITION(p1, p2, ...)]
Note:
- This statement is used to truncate data while retaining tables or partitions.
- Unlike DELETE, this statement can only empty the specified tables or partitions as a whole, and filtering conditions cannot be added.
- Unlike DELETE, using this method to clear data will not affect query performance.
- This statement directly deletes data. The deleted data cannot be recovered.
- The table on which you perform this operation must be in the NORMAL state. For example, you cannot perform TRUNCATE TABLE on a table with SCHEMA CHANGE going on.
Examplesβ
-
Truncate table
tblunderexample_db.TRUNCATE TABLE example_db.tbl; -
Truncate partitions
p1andp2in tabletbl.TRUNCATE TABLE tbl PARTITION(p1, p2);