Renaming a table
Warning
Supported only for row-oriented tables. Support for column-oriented tables is currently under development.
ALTER TABLE old_table_name RENAME TO new_table_name;
See table and column naming rules
Database object naming rules
Every scheme object in YDB has a name. In YQL statements, object names are specified by identifiers that can be enclosed in backticks or not. For more information on identifiers, refer to Keywords and identifiers.
Scheme object names in YDB must meet the following requirements:
- Object names can include the following characters:
- uppercase latin characters
- lowercase latin characters
- digits
- special characters:
.
,-
, and_
.
- Object name length must not exceed 255 characters.
- Objects cannot be created in folders, which names start with a dot, such as
.sys
,.medatata
,.sys_health
.
Column naming rules
Column names in YDB must meet the following requirements:
- Column names can include the following characters:
- uppercase latin characters
- lowercase latin characters
- digits
- special characters:
-
and_
.
- Column names must not start with the system prefix
__ydb_
.
If a table with the new name already exists, an error will be returned. The ability to transactionally replace a table under load is supported by specialized methods in CLI and SDK.
Warning
If a YQL query contains multiple ALTER TABLE ... RENAME TO ...
commands, each will be executed in auto-commit mode in a separate transaction. From the perspective of an external process, the tables will be renamed sequentially, one after another. To rename multiple tables in a single transaction, use specialized methods available in CLI and SDK.
Renaming can be used to move a table from one directory within the database to another, for example:
ALTER TABLE `table1` RENAME TO `/backup/table1`;