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.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | DROP TABLE IF EXISTS customer_address; CREATE TABLE customer_address ( ca_address_sk INTEGER NOT NULL , ca_address_id CHARACTER(16) NOT NULL , ca_street_number CHARACTER(10) , ca_street_name CHARACTER varying(60) , ca_street_type CHARACTER(15) , ca_suite_number CHARACTER(10) ) DISTRIBUTE BY HASH (ca_address_sk) PARTITION BY RANGE(ca_address_sk) ( PARTITION P1 VALUES LESS THAN(2450815), PARTITION P2 VALUES LESS THAN(2451179), PARTITION P3 VALUES LESS THAN(2451544), PARTITION P4 VALUES LESS THAN(MAXVALUE) ); |
Clear the p1 partition of the customer_address table:
1 | ALTER TABLE customer_address TRUNCATE PARTITION p1; |
Clear a partitioned table:
1 | TRUNCATE TABLE customer_address; |