2021-08-01 13:02:35 +00:00
|
|
|
---
|
2022-08-28 14:53:34 +00:00
|
|
|
slug: /en/sql-reference/statements/exchange
|
2022-04-09 13:29:05 +00:00
|
|
|
sidebar_position: 49
|
|
|
|
sidebar_label: EXCHANGE
|
2021-08-01 13:02:35 +00:00
|
|
|
---
|
|
|
|
|
2022-06-02 10:55:18 +00:00
|
|
|
# EXCHANGE Statement
|
2021-08-01 13:02:35 +00:00
|
|
|
|
2021-08-01 16:17:50 +00:00
|
|
|
Exchanges the names of two tables or dictionaries atomically.
|
2021-08-03 20:05:32 +00:00
|
|
|
This task can also be accomplished with a [RENAME](./rename.md) query using a temporary name, but the operation is not atomic in that case.
|
2021-08-01 13:02:35 +00:00
|
|
|
|
2022-04-09 13:29:05 +00:00
|
|
|
:::note
|
|
|
|
The `EXCHANGE` query is supported by the [Atomic](../../engines/database-engines/atomic.md) database engine only.
|
|
|
|
:::
|
2021-08-01 13:02:35 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
2022-07-06 23:41:01 +00:00
|
|
|
EXCHANGE TABLES|DICTIONARIES [db0.]name_A AND [db1.]name_B [ON CLUSTER cluster]
|
2021-08-01 13:02:35 +00:00
|
|
|
```
|
|
|
|
|
2022-06-02 10:55:18 +00:00
|
|
|
## EXCHANGE TABLES
|
2021-08-01 13:02:35 +00:00
|
|
|
|
2021-08-01 16:17:50 +00:00
|
|
|
Exchanges the names of two tables.
|
2021-08-01 13:02:35 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
2022-07-06 23:41:01 +00:00
|
|
|
EXCHANGE TABLES [db0.]table_A AND [db1.]table_B [ON CLUSTER cluster]
|
2021-08-01 13:02:35 +00:00
|
|
|
```
|
|
|
|
|
2022-06-02 10:55:18 +00:00
|
|
|
## EXCHANGE DICTIONARIES
|
2021-08-01 13:02:35 +00:00
|
|
|
|
2021-08-01 16:17:50 +00:00
|
|
|
Exchanges the names of two dictionaries.
|
2021-08-01 13:02:35 +00:00
|
|
|
|
|
|
|
**Syntax**
|
|
|
|
|
|
|
|
```sql
|
2022-07-06 23:41:01 +00:00
|
|
|
EXCHANGE DICTIONARIES [db0.]dict_A AND [db1.]dict_B [ON CLUSTER cluster]
|
2021-08-01 13:02:35 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
**See Also**
|
|
|
|
|
2023-04-19 15:55:29 +00:00
|
|
|
- [Dictionaries](../../sql-reference/dictionaries/index.md)
|