You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
DDL
Detach statement (DETACH)
Copy page
Download PDF
Detach statement (DETACH)

Detach a table, materialized view, Dictionary, or Database.
Syntax

DETACH TABLE|VIEW|DICTIONARY|DATABASE [IF EXISTS] [db.]name  [PERMANENTLY] [SYNC]

The detach operation does not delete the data or metadata of the table, materialized view, Dictionary, or Database. If the entity is not permanently detached, the server will read the metadata and re-identify the table, view, Dictionary, or Database the next time it starts. If the entity is permanently detached, it will not be automatically re-identified.
Regardless of whether the table, Dictionary, or Database is permanently detached, you can use the ATTACH query to re-attach them. System log tables, such as query_log, text_log, and others, can also be re-attached. Other system tables cannot be re-attached. The server will re-identify these tables the next time it starts.
Caution: You cannot permanently detach a table that has already been detached (temporarily). However, you can re-attach it first and then detach it permanently again.
In addition, you cannot delete a detached table, create a table with the same name as a permanently detached table, or use the RENAME TABLE query to replace it with another table.
The SYNC modifier executes the operation immediately.
Example
Create a table:

CREATE TABLE db1.test (i Int64) ENGINE = CnchMergeTree() ORDER BY i 
INSERT INTO db1.test  SELECT number FROM numbers(10); 
SELECT * FROM db1.test; 

┌─number─┐ 
│      0 │ 
│      1 │ 
│      2 │ 
│      3 │ 
│      4 │ 
│      5 │ 
│      6 │ 
│      7 │ 
│      8 │ 
│      9 │ 
└────────┘

Detach a table
Query statement:

DETACH TABLE test; 
SELECT * FROM test;

Result:

Received exception from server (version 21.4.1): 
Code: 60. DB::Exception: Received from localhost:9000. DB::Exception: Table default.test does not exist.
Last updated: 2026.03.31 10:31:07