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

63 lines
1.6 KiB
Markdown
Raw Normal View History

2020-07-11 11:05:49 +00:00
---
sidebar_position: 48
sidebar_label: RENAME
2020-07-11 11:05:49 +00:00
---
2022-06-02 10:55:18 +00:00
# RENAME Statement
2020-07-11 11:05:49 +00:00
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 entities names atomically, use the [EXCHANGE](./exchange.md) statement.
2021-08-01 13:02:35 +00:00
:::note
The `RENAME` query is supported by the [Atomic](../../engines/database-engines/atomic.md) database engine only.
:::
2021-08-01 13:02:35 +00:00
**Syntax**
```sql
RENAME DATABASE|TABLE|DICTIONARY name TO new_name [,...] [ON CLUSTER cluster]
```
2022-06-02 10:55:18 +00:00
## RENAME DATABASE
2021-08-01 16:17:50 +00:00
Renames databases.
2021-08-01 13:02:35 +00:00
**Syntax**
2021-08-01 16:17:50 +00:00
```sql
2021-08-01 13:02:35 +00:00
RENAME DATABASE atomic_database1 TO atomic_database2 [,...] [ON CLUSTER cluster]
```
2022-06-02 10:55:18 +00:00
## RENAME TABLE
2021-08-01 13:02:35 +00:00
2020-07-11 11:05:49 +00:00
Renames one or more tables.
2021-08-01 16:17:50 +00:00
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.
2021-08-01 13:02:35 +00:00
**Syntax**
2020-07-11 11:05:49 +00:00
``` sql
2021-08-01 13:02:35 +00:00
RENAME TABLE [db1.]name1 TO [db2.]name2 [,...] [ON CLUSTER cluster]
2020-07-11 11:05:49 +00:00
```
2021-08-01 13:02:35 +00:00
**Example**
```sql
RENAME TABLE table_A TO table_A_bak, table_B TO table_B_bak;
```
2022-06-02 10:55:18 +00:00
## RENAME DICTIONARY
2021-08-01 13:02:35 +00:00
Renames one or several dictionaries. This query can be used to move dictionaries between databases.
**Syntax**
```sql
RENAME DICTIONARY [db0.]dict_A TO [db1.]dict_B [,...] [ON CLUSTER cluster]
```
**See Also**
- [Dictionaries](../../sql-reference/dictionaries/index.md)