TRUNCATE TABLE Statement

The TRUNCATE TABLE statement deletes table data but does not delete the table structure. You can also execute the DROP TABLE statement to delete a table. However, this statement deletes the table structure together with the table. To insert data into the table, you need to recreate the table.

It has the same effect as an unqualified DELETE statement on each table, but it is faster since it does not actually scan the tables. This is most useful on large tables. In addition, the TRUNCATE TABLE statement immediately releases tablespaces without requiring subsequent VACUUM operations.

Syntax

TRUNCATE TABLE  table_name ;

Parameter Description

  • table_name

    Specifies the name (optionally schema-qualified) of the target table.

    Value range: an existing table name

Examples

Execute the TRUNCATE TABLE statement to delete data from the customer_t1 table.

openGauss=# TRUNCATE TABLE customer_t1;
TRUNCATE TABLE

Query the customer_t1 table. The query result is as follows:

openGauss=# SELECT * FROM customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
(0 rows)
Feedback
编组 3备份
    openGauss 2024-05-07 00:46:52
    cancel