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
tbl
underexample_db
.TRUNCATE TABLE example_db.tbl;
-
Truncate partitions
p1
andp2
in tabletbl
.TRUNCATE TABLE tbl PARTITION(p1, p2);