Deleting Data with TRUNCATE Command
Truncate
This statement is used to clear the data of a specified table or partition in Doris
Syntax
TRUNCATE TABLE [db.]tbl[ PARTITION(p1, p2, ...)];
- This statement only clears the data within a table or partition but preserves the table or partition itself.
- Unlike DELETE, this statement can only clear the specified table or partition as a whole and cannot be added with filter conditions.
- Unlike DELETE, truncating data will not affect query performance.
- The data deleted by this operation is not recoverable.
- When using this command, the table status must be NORMAL, which means that tables undergoing SCHEMA CHANGE can not be truncated.
- This command may cause ongoing imports to fail.
Example
- Truncate the table
tbl
underexample_db
.
TRUNCATE TABLE example_db.tbl;
- Truncate partitions
p1
andp2
of tabletbl
.
TRUNCATE TABLE tbl PARTITION(p1, p2);