Rename a database, table, or dictionary. Multiple entities can be renamed in a single query.
tip
Please note that a RENAME query with multiple entities is a non-atomic operation.
:::
Rename a database.
Syntax
RENAME DATABASE atomic_database1 TO atomic_database2 [,...]
Rename one or more tables.
Renaming a table is a lightweight operation. If a different database is specified after TO, the table will be moved to that database.** However, the directory containing the database must be located on the same file system. Otherwise, an error is returned. If multiple tables are renamed in a single query, the operation is not atomic. **The operation may be partially executed, and other sessions may receive Table ... does not exist ... errors.
Syntax
RENAME TABLE [tableIdentifier] TO [tableIdentifier], [tableIdentifier] TO [tableIdentifier]
Example
-- step 1: create a table CREATE TABLE `example_table` ( `a` Int8, `b` String, `c` Date ) ENGINE = `CnchMergeTree` ORDER BY (`a`) -- step 2: rename the new created table RENAME TABLE example_table to new_table_name
Rename one or more dictionaries. This query can be used to move dictionaries between databases.
Syntax
RENAME DICTIONARY [db0.]dict_A TO [db1.]dict_B [,...]