ClickHouse/docs/en/sql-reference/statements/detach.md

43 lines
2.2 KiB
Markdown
Raw Normal View History

2020-07-11 11:05:49 +00:00
---
toc_priority: 43
2020-07-23 20:02:54 +00:00
toc_title: DETACH
2020-07-11 11:05:49 +00:00
---
# DETACH Statement {#detach}
Deletes information about the table or view from the server. The server stops knowing about their existence.
2021-02-15 21:32:39 +00:00
Syntax:
2020-07-11 11:05:49 +00:00
``` sql
DETACH TABLE|VIEW [IF EXISTS] [db.]name [PERMANENTLY] [ON CLUSTER cluster]
2020-07-11 11:05:49 +00:00
```
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](../../sql-reference/statements/attach.md) query (with the exception of system tables, which do not have metadata stored for them).
`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](../../sql-reference/statements/drop.md#drop-table) the detached table, or [CREATE TABLE](../../sql-reference/statements/create/table.md) with the same name as detached permanently, or replace it with the other table with [RENAME TABLE](../../sql-reference/statements/rename.md) query.
2020-07-11 11:05:49 +00:00
2021-02-16 10:23:52 +00:00
Similarly, a “detached” table can be re-attached using the [ATTACH](../../sql-reference/statements/attach.md) query (with the exception of system tables, which do not have metadata stored for them).
2021-02-15 21:32:39 +00:00
2021-02-16 10:33:20 +00:00
## DETACH PERMANENTLY {#detach-permanently}
2021-02-15 21:32:39 +00:00
2021-02-16 10:33:20 +00:00
Deletes information about `name` table or view from the server. Permanently detached tables won't automatically reappear after the server restart.
2021-02-15 21:32:39 +00:00
Syntax:
``` sql
DETACH TABLE/VIEW [IF EXISTS] [db.]name PERMAMENTLY [ON CLUSTER cluster]
```
This statement does not delete the tables data or metadata.
2021-02-16 10:33:20 +00:00
Permanently detached table or view can be reattached with [ATTACH](../../sql-reference/statements/attach.md) query and can be shown with [SHOW CREATE TABLE](../../sql-reference/statements/show.md#show-create-table) query.
2021-02-15 21:32:39 +00:00
[Original article](https://clickhouse.tech/docs/en/sql-reference/statements/detach/) <!--hide-->