TRUNCATE v17

Name

TRUNCATE Empty a table.

Synopsis

TRUNCATE TABLE <name> [DROP STORAGE]

Description

TRUNCATE removes all rows from a table. It has the same effect as an unqualified DELETE. However, since it doesn't scan the table, it's faster. TRUNCATE is most useful on large tables.

The DROP STORAGE clause is accepted for compatibility but is ignored.

Parameters

name

The name (optionally schema-qualified) of the table to truncate.

Notes

You can't use TRUNCATE if there are foreign-key references to the table from other tables. Checking validity in such cases requires table scans, which TRUNCATE aims to avoid.

TRUNCATE doesn't run any user-defined ON DELETE triggers for the table.

Examples

This command truncates a table named accounts:

TRUNCATE TABLE accounts;

See also

DROP VIEW, DELETE