TRUNCATE

Function

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.

Precautions

Syntax

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  [, ...] )  } ;

Parameter Description

Examples

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;