DROP TABLE permanently removes a table and its data from a ClickHouse database.
DROP TABLE instantly deletes the table structure and all stored data, freeing disk space and preventing further queries on the table. Use it when a table is obsolete or recreated elsewhere.
Write DROP TABLE [IF EXISTS] [db.]table_name [ON CLUSTER cluster_name] [NO DELAY]
. Add IF EXISTS
to avoid errors if the table is missing.Use ON CLUSTER
to drop tables across a cluster.
Wrap the command in a transaction-safe environment or back up data first. In production, combine IF EXISTS
and run during low-traffic windows.
Yes. Execute DROP commands for both the distributed and underlying local tables. Use ON CLUSTER
to ensure consistency across shards.
1) Stop writes to Orders
. 2) Back up recent partitions.3) Run DROP TABLE IF EXISTS Orders ON CLUSTER company_cluster
. 4) Verify with SHOW TABLES
.
Always qualify the database (e.g., analytics.Orders
) to avoid dropping similarly named tables in other DBs. Maintain a change log for auditing.
DROP TABLE fails if materialized views depend on it. Drop or detach the views first, or use DETACH TABLE
to keep metadata while removing data.
Recovery requires restoring from backup or replicated replicas.ClickHouse lacks an inherent UNDO, reinforcing the need for backups.
.
No. Restore from backup or replication.
It locks only the target table; other tables remain available.
NO DELAY skips waiting for asynchronous parts cleanup, returning faster but cleaning later.