TRUNCATE quickly removes all rows from a database table.
It has the same effect as an unqualified DELETE on each table, but it is faster since it does not actually scan the tables. This is most useful on large tables.
TRUNCATE obtains an ACCESS EXCLUSIVE lock on each table it operates on, which blocks all other concurrent operations on that table. If concurrent access to the table is required, use the DELETE command instead.
1 2 | TRUNCATE [ TABLE ] [ ONLY ] {[[database_name.]schema_name.]table_name [ * ]} [, ... ] [ CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]; |
1 2 3 4 5 | ALTER TABLE [ IF EXISTS ] { [ ONLY ] [[database_name.]schema_name.]table_name | table_name * | ONLY ( table_name ) } TRUNCATE PARTITION { partition_name | FOR ( partition_value [, ...] ) } ; |
If ONLY is specified, only the specified table is cleared. Otherwise, the table and all its subtables (if any) are cleared.
Database name of the target table
Schema name of the target table
Specifies the name (optionally schema-qualified) of a target table.
Value range: an existing table name
Does not change the values of sequences. This is the default.
Indicates the partition in the target partition table.
Value range: An existing partition name.
Specifies the value of the specified partition key.
The value specified by PARTITION FOR can uniquely identify a partition.
Value range: The partition key of the partition to be deleted.
When the PARTITION FOR clause is used, the entire partition where partition_value is located is cleared.
Clear the p1 partition of the customer_address table.
1 | ALTER TABLE tpcds.customer_address TRUNCATE PARTITION p1; |
Clear a partitioned table.
1 | TRUNCATE TABLE tpcds.customer_address; |