Truncate allows the data in a table or database to be removed, while preserving their existence. This is a lightweight operation which can’t be reversed. TheDocumentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
TRUNCATE statement in ClickHouse is used to quickly remove all data from a table or database while preserving their structure.
TRUNCATE TABLE
| Parameter | Description |
|---|---|
IF EXISTS | Prevents an error if the table does not exist. If omitted, the query returns an error. |
db.name | Optional database name. |
ON CLUSTER cluster | Runs the command across a specified cluster. |
SYNC | Makes the truncation synchronous across replicas when using replicated tables. If omitted, truncation happens asynchronously by default. |
TRUNCATE queries with the replication_wait_for_inactive_replica_timeout setting.
If the
alter_sync is set to 2 and some replicas are not active for more than the time, specified by the replication_wait_for_inactive_replica_timeout setting, then an exception UNFINISHED is thrown.TRUNCATE TABLE query is not supported for the following table engines:
TRUNCATE ALL TABLES
| Parameter | Description |
|---|---|
ALL | Removes data from all tables in the database. |
IF EXISTS | Prevents an error if the database does not exist. |
db | The database name. |
LIKE | ILIKE | NOT LIKE '<pattern>' | Filters tables by pattern. |
ON CLUSTER cluster | Runs the command across a cluster. |
TRUNCATE DATABASE
| Parameter | Description |
|---|---|
IF EXISTS | Prevents an error if the database does not exist. |
db | The database name. |
ON CLUSTER cluster | Runs the command across a specified cluster. |
IF EXISTS is omitted, the query returns an error if the database does not exist.
TRUNCATE DATABASE is not supported for Replicated databases. Instead, just DROP and CREATE the database.