TRUNCATE TABLE

statementsupportedTables, views, streams, sequences

docs.snowflake.com ↗

Removes all rows from a table but leaves the table intact (including all privileges and constraints on the table). Also deletes the load metadata for the table, which allows the same files to be loaded into the table again after the command completes. Note that this is different from DROP TABLE, which removes the table from the system but retains a version of the table (along with its load history) so that they can be recovered.

Syntax

supportedpartialnot supportednot scored

TRUNCATE [ TABLE ] [ IF EXISTS ] <name>

TRUNCATE [ TABLE ] [ IF EXISTS ] ERROR_TABLE( <base_table_name> )

Parameters

NameRequiredDescription
nameSpecifies the identifier for the table to truncate. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive (for example, "My Object"). If the table identifier is not fully-qualified (in the form of db_name.schema_name.table_name or schema_name.table_name), the command looks for the table in the current schema for the session.
ERROR_TABLE( base_table_name )Truncates the error table associated with the specified base table. It doesn’t delete the rows or the load metadata of the base table. For more information about error tables, see Error tables. To clear the error table after you load the rows that COPY INTO or Snowpipe rejected, see Clear the error table and resume loads. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive (for example, "My Object"). If the table identifier is not fully-qualified (in the form of db_name.schema_name.table_name or schema_name.table_name), the command looks for the table in the current schema for the session.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes TRUNCATE | Table | Required on the table to truncate, unless the role owns the table. Truncating an error table with ERROR_TABLE( <base_table_name> ) requires the TRUNCATE or OWNERSHIP privilege on the base table. The SELECT ERROR TABLE privilege isn’t enough. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

See also

Referenced by