Reference: Truncate Statement
Truncate allows clearing all data from a table.
Usage example:
truncate movies, stars, starsIn;This removes all rows from the specified tables, similar to an unqualified
delete.
TRUNCATE is transactional: a ROLLBACK restores the rows.
TRUNCATE [ TABLE ] [ ONLY ] <name> [, ...] [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]You cannot truncate a table that a foreign key of another table references, even if the referencing table is empty or listed in the same statement, and also not with CASCADE.
Use DELETE for such tables.
Truncate is a destructive operation and will cause all data in the specified tables to be lost.
Permissions
To truncate a table, you need the TRUNCATE privilege on it.
PostgreSQL Differences
RESTART IDENTITYis accepted, but identity columns and sequences continue with their current value. Reset them withALTER SEQUENCE <table>_<column>_seq RESTART.- Tables referenced by a foreign key cannot be truncated, even with
CASCADEor when all referencing tables are truncated in the same statement. - Truncate is transactional in CedarDB and can be rolled back.