ClickHouse/docs/en/sql-reference/statements/detach.md
2021-03-08 19:40:05 +03:00

1.6 KiB

toc_priority toc_title
43 DETACH

DETACH Statement

Deletes information about the table or view from the server. The server stops knowing about their existence.

Syntax:

DETACH TABLE|VIEW [IF EXISTS] [db.]name [PERMANENTLY] [ON CLUSTER cluster]

Detaching does not delete the data or metadata for the table or view. If the table or view was not detached PERMANENTLY, on the next server launch the server will read the metadata and recall the table/view again. If the table or view was detached PERMANENTLY, there will be no automatic recall.

Whether the table was detached permanently or not, in both cases you can reattach it using the ATTACH. System log tables can be also attached back (e.g. query_log, text_log, etc). Other system tables can't be reattached. On the next server launch the server will recall those tables again.

ATTACH MATERIALIZED VIEW doesn't work with short syntax (without SELECT), but you can attach it using the ATTACH TABLE query.

Note that you can not detach permanently the table which is already detached (temporary). But you can attach it back and then detach permanently again.

Also you can not DROP the detached table, or CREATE TABLE with the same name as detached permanently, or replace it with the other table with RENAME TABLE query.

Original article