Click here to go to the PostgreSQL specification for this syntax.
Sample codes scenarios
Basic use without options
-- TABLE without descendantsTRUNCATETABLE mytable;-- TABLE with descendantsTRUNCATETABLE table_with_descendants;
-- TABLE without descendantsTRUNCATE mytable;-- TABLE with descendantsTRUNCATE descendant_table;TRUNCATE table_with_descendants;
Using ONLY Option
This will generate that the first table
-- TABLE without descendantsTRUNCATETABLE ONLY mytable;-- TABLE with descendantsTRUNCATETABLE ONLY table_with_descendants;
-- TABLE without descendants--** MSC-WARNING - MSCEWI1102 - REMOVED ONLY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATETABLE mytable;-- TABLE with descendants--** MSC-WARNING - MSCEWI1102 - REMOVED ONLY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATETABLE table_with_descendants;
Without table keyword
-- TABLE without descendantsTRUNCATE mytable;-- TABLE with descendantsTRUNCATE table_with_descendants;
-- TABLE without descendantsTRUNCATE mytable;-- TABLE with descendantsTRUNCATE descendant_table;TRUNCATE table_with_descendants;
-- TABLE without descendantsTRUNCATETABLE mytable *;-- TABLE with descendantsTRUNCATETABLE table_with_descendants *;
-- TABLE without descendantsTRUNCATETABLE mytable;-- TABLE with descendantsTRUNCATETABLE descendant_table;TRUNCATETABLE table_with_descendants;
Only option should apply to the first specified table when using lists
-- Case 1:TRUNCATE ONLY mytable, table_with_descendants;-- Case 2:TRUNCATE ONLY table_with_descendants, mytable;
-- Case 1:--** MSC-WARNING - MSCEWI1102 - REMOVED ONLY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATE mytable;TRUNCATE descendant_table;TRUNCATE table_with_descendants;-- Case 2:--** MSC-WARNING - MSCEWI1102 - REMOVED ONLY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATE table_with_descendants;TRUNCATE mytable;
Use RESTART OPTION for tables
When using [RESTART IDENTITY] automatically restarts the sequences owned by columns of the truncated tables
--** MSC-WARNING - MSCEWI1102 - REMOVED RESTART IDENTITY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **
TRUNCATETABLE mytable;CREATE OR REPLACESEQUENCEtable_with_identity_didSTART1 CLONE table_with_identity_did;ALTERTABLE table_with_identity ALTER did SETDEFAULT table_with_identity_did.NEXTVAL;TRUNCATETABLE table_with_identity;
Use CONTINUE OPTION for tables
When using [CONTINUE IDENTITY] does not changes the values of the sequence
TRUNCATETABLE ONLY table_with_identity CONTINUEIDENTITY;
--** MSC-WARNING - MSCEWI1102 - REMOVED ONLY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **--** MSC-WARNING - MSCEWI1102 - REMOVED CONTINUE IDENTITY OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **
TRUNCATETABLE table_with_identity;
Use CASCADE for tables
When a CASCADE OPTION is specified all tables related by a foreign key will be truncated
-- Case 1:TRUNCATE mytable CASCADE;-- Case 2:TRUNCATE table_with_identity CASCADE;
-- Case 1:--** MSC-WARNING - MSCEWI1102 - REMOVED CASCADE OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATE mytable;-- Case 2:--** MSC-WARNING - MSCEWI1102 - REMOVED CASCADE OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATE table_with_foreign_key;TRUNCATE table_with_identity;
Use RESTRICTED for tables
When a table has references a EWI is added to be reviewed.
--** MSC-WARNING - MSCEWI1102 - REMOVED RESTRICT OPTION FROM CODE, ALREADY HANDLED IN CONVERSION TO SNOWFLAKE **TRUNCATE mytable;--** MSC-WARNING - MSC-PG0028 - THE TRUNCATE RESTRICTED BEHAVIOR SHOULD BE USED WHEN TABLE HAS NOT REFERENCES, IF HAVE REFERENCES PLEASE ADDED. **
TRUNCATE table_with_identity;