RENAME DATABASE

On this page Carat arrow pointing down
Warning:
As of November 10, 2018, CockroachDB v1.0 is no longer supported. For more details, refer to the Release Support Policy.

The RENAME DATABASE statement changes the name of a database.

Note:
It is not possible to rename a database referenced by a view. For more details, see View Dependencies.

Synopsis

ALTER DATABASE name RENAME TO name

Required Privileges

Only the root user can rename databases.

Parameters

Parameter Description
name The first instance of name is the current name of the database. The second instance is the new name for the database. The new name must be unique and follow these identifier rules.

Examples

Rename a Database

> SHOW DATABASES;
+----------+
| Database |
+----------+
| db1      |
| db2      |
| system   |
+----------+
> ALTER DATABASE db1 RENAME TO db3;
RENAME DATABASE
> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2      |
| db3      |
| system   |
+----------+

Rename Fails (New Name Already In Use)

> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2      |
| db3      |
| system   |
+----------+
> ALTER DATABASE db2 RENAME TO db3;
pq: the new database name "db3" already exists

See Also


Yes No
On this page

Yes No