This commit is contained in:
Alexey 2021-08-01 16:17:50 +00:00
parent 0a36d8a607
commit 722e092059
4 changed files with 20 additions and 20 deletions

View File

@ -10,12 +10,12 @@ Attaches a table or a dictionary, for example, when moving a database to another
**Syntax**
``` sql
ATTACH TABLE|DICTIONARY [IF NOT EXISTS] [db.]name [ON CLUSTER cluster]
ATTACH TABLE|DICTIONARY [IF NOT EXISTS] [db.]name [ON CLUSTER cluster] ...
```
The query does not create data on the disk, but assumes that data is already in the appropriate places, and just adds information about the table to the server. After executing an `ATTACH` query, the server will know about the existence of the table.
The query does not create data on the disk, but assumes that data is already in the appropriate places, and just adds information about the table or the dictionary to the server. After executing the `ATTACH` query, the server will know about the existence of the table or the dictionary.
If a table or a dictionary was previously detached ([DETACH](../../sql-reference/statements/detach.md) query), meaning that its structure is known, you can use shorthand without defining the structure.
If a table was previously detached ([DETACH](../../sql-reference/statements/detach.md) query), meaning that its structure is known, you can use shorthand without defining the structure.
## Attach Existing Table {#attach-existing-table}
@ -29,7 +29,7 @@ This query is used when starting the server. The server stores table metadata as
If the table was detached permanently, it won't be reattached at the server start, so you need to use `ATTACH` query explicitly.
## Сreate New Table And Attach Data {#create-new-table-and-attach-data}
## Create New Table And Attach Data {#create-new-table-and-attach-data}
**With specify path to table data**

View File

@ -7,15 +7,15 @@ toc_title: DETACH
Makes the server "forget" about the existence of a table, a materialized view or a dictionary.
Syntax:
**Syntax**
``` sql
DETACH TABLE|VIEW|DICTIONARY [IF EXISTS] [db.]name [ON CLUSTER cluster] [PERMANENTLY]
```
Detaching does not delete the data or metadata of the table, the materialized view or the dictionary. If the entity was not detached `PERMANENTLY`, on the next server launch the server will read the metadata and recall the table/view/dictionary again. If the entiry was detached `PERMANENTLY`, there will be no automatic recall.
Detaching does not delete the data or metadata of the table, the materialized view or the dictionary. If the entity was not detached `PERMANENTLY`, on the next server launch the server will read the metadata and recall the table/view/dictionary again. If the entity was detached `PERMANENTLY`, there will be no automatic recall.
Whether a table or a dictionary was detached permanently or not, in both cases you can reattach them using the [ATTACH](../../sql-reference/statements/attach.md).
Whether a table or a dictionary was detached permanently or not, in both cases you can reattach them using the [ATTACH](../../sql-reference/statements/attach.md) query.
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` does not work with short syntax (without `SELECT`), but you can attach it using the `ATTACH TABLE` query.
@ -70,6 +70,6 @@ Code: 60. DB::Exception: Received from localhost:9000. DB::Exception: Table defa
**See Also**
- [Materialized View](../../sql-reference/statements/create/view.md/#materialized)
- [Materialized View](../../sql-reference/statements/create/view.md#materialized)
- [Dictionaries](../../sql-reference/dictionaries/index.md)

View File

@ -5,10 +5,11 @@ toc_title: EXCHANGE
# EXCHANGE Statement {#exchange}
Exchanges names of two tables or dictionaries in an atomic query.
Exchanges the names of two tables or dictionaries atomically.
This task can also be accomplished with a [RENAME](./rename.md) query using a temporary name. But the operation in not atomic in that case.
!!! note "Note"
An `EXCHANGE` query is supported by [Atomic](../../engines/database-engines/atomic.md) database engine only.
The `EXCHANGE` query is supported by the [Atomic](../../engines/database-engines/atomic.md) database engine only.
**Syntax**
@ -18,7 +19,7 @@ EXCHANGE TABLES|DICTIONARIES [db0.]name_A AND [db1.]name_B
## EXCHANGE TABLES {#exchange_tables}
Exchanges names of two tables in an atomic query.
Exchanges the names of two tables.
**Syntax**
@ -28,7 +29,7 @@ EXCHANGE TABLES [db0.]table_A AND [db1.]table_B
## EXCHANGE DICTIONARIES {#exchange_dictionaries}
Exchanges names of two dictionaries in an atomic query.
Exchanges the names of two dictionaries.
**Syntax**

View File

@ -5,11 +5,11 @@ toc_title: RENAME
# RENAME Statement {#misc_operations-rename}
Renames databases, tables and dictionaries. Several entities can be renamed in a single query.
Renames databases, tables or dictionaries. Several entities can be renamed in a single query.
Note that the `RENAME` query with several entities is non-atomic operation. To swap entity names atomically, use [EXCHANGE](./exchange.md) statement.
!!! note "Note"
A `RENAME` query is supported by [Atomic](../../engines/database-engines/atomic.md) database engine only.
The `RENAME` query is supported by the [Atomic](../../engines/database-engines/atomic.md) database engine only.
**Syntax**
@ -19,12 +19,11 @@ RENAME DATABASE|TABLE|DICTIONARY name TO new_name [,...] [ON CLUSTER cluster]
## RENAME DATABASE {#misc_operations-rename_database}
Renames databases. I
Renames databases.
**Syntax**
sql
```
```sql
RENAME DATABASE atomic_database1 TO atomic_database2 [,...] [ON CLUSTER cluster]
```
@ -32,15 +31,15 @@ RENAME DATABASE atomic_database1 TO atomic_database2 [,...] [ON CLUSTER cluster]
Renames one or more tables.
Renaming tables is a light operation. If you pass a different database after `TO`, the table will be moved to this database. However, the directories with databases must reside in the same file system. Otherwise, an error is returned.
If you rename multiple tables in one query, the operation is not atomic. It may be partially executed, and queries in other sessions may get `Table ... does not exist ...` error.
**Syntax**
``` sql
RENAME TABLE [db1.]name1 TO [db2.]name2 [,...] [ON CLUSTER cluster]
```
Renaming tables is a light operation. If you pass a different database after `TO`, the table will be moved to this database. However, the directories with databases must reside in the same file system. Otherwise, an error is returned.
If you rename multiple tables in one query, this is a non-atomic operation, it may be partially executed, queries in other sessions may receive the error `Table ... does not exist ..`.
**Example**
```sql