RENAME COLUMN

On this page Carat arrow pointing down
Warning:
As of April 12, 2019, CockroachDB v1.1 is no longer supported. For more details, refer to the Release Support Policy.

The RENAME COLUMN statement changes the name of a column in a table.

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

Synopsis

ALTER TABLE IF EXISTS table_name RENAME COLUMN current_name TO name

Required Privileges

The user must have the CREATE privilege on the table.

Parameters

Parameter Description
IF EXISTS Rename the column only if a column of current_name exists; if one does not exist, do not return an error.
table_name The name of the table with the column you want to use.
current_name The current name of the column.
name The name you want to use for the column, which must be unique to its table and follow these identifier rules.

Viewing Schema Changes New in v1.1

Whenever you initiate a schema change, CockroachDB registers it as a job, which you can view with SHOW JOBS.

Example

Rename a Column

> SELECT * FROM users;
+----+-------+-------+
| id | name  | title |
+----+-------+-------+
|  1 | Tom   | cat   |
|  2 | Jerry | rat   |
+----+-------+-------+
> ALTER TABLE users RENAME COLUMN title TO species;
> SELECT * FROM users;
+----+-------+---------+
| id | name  | species |
+----+-------+---------+
|  1 | Tom   | cat     |
|  2 | Jerry | rat     |
+----+-------+---------+

See Also


Yes No
On this page

Yes No