TRUNCATE

Description

Statement use to empty a table or set of tables.

Grammar Syntax

TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]
    [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]

Click here to go to the PostgreSQL specification for this syntax.

Sample codes scenarios

Basic use without options

-- TABLE without descendants
TRUNCATE TABLE mytable;

-- TABLE with descendants
TRUNCATE TABLE table_with_descendants;

Using ONLY Option

This will generate that the first table

Without table keyword

For a list of multiple tables

Using explicit `*` include descendants

Only option should apply to the first specified table when using lists

Use RESTART OPTION for tables

When using [RESTART IDENTITY] automatically restarts the sequences owned by columns of the truncated tables

Use CONTINUE OPTION for tables

When using [CONTINUE IDENTITY] does not changes the values of the sequence

Use CASCADE for tables

When a CASCADE OPTION is specified all tables related by a foreign key will be truncated

Use RESTRICTED for tables

When a table has references a EWI is added to be reviewed.

Last updated

Was this helpful?