ALTER TABLE

On this page Carat arrow pointing down
Warning:
CockroachDB v22.1 is no longer supported as of November 24, 2023. For more details, refer to the Release Support Policy.

The ALTER TABLE statement changes the definition of a table. For information on using ALTER TABLE, see the pages for its subcommands.

Note:

The ALTER TABLE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Subcommands

Tip:

Some subcommands can be used in combination in a single ALTER TABLE statement. For example, you can atomically rename a column and add a new column with the old name of the existing column.

Subcommand Description Can combine with other subcommands?
ADD COLUMN Add columns to tables. Yes
ADD CONSTRAINT Add constraints to columns. Yes
ALTER COLUMN Change an existing column. Yes
ALTER PRIMARY KEY Change the primary key of a table. Yes
DROP COLUMN Remove columns from tables. Yes
DROP CONSTRAINT Remove constraints from columns. Yes
EXPERIMENTAL_AUDIT Enable per-table audit logs, for security purposes. Yes
OWNER TO Change the owner of the table.
PARTITION BY Partition, re-partition, or un-partition a table (Enterprise-only). Yes
RENAME COLUMN Change the names of columns. Yes
RENAME CONSTRAINT Change constraints columns. Yes
RENAME TO Change the names of tables. No
RESET (storage parameter) Reset a storage parameter on a table to its default value. Yes
SET SCHEMA Change the schema of a table. No
SPLIT AT Force a range split at the specified row in the table. No
UNSPLIT AT Remove a range split enforcement in the table. No
VALIDATE CONSTRAINT Check whether values in a column match a constraint on the column. Yes
SET LOCALITY {REGIONAL BY TABLE, REGIONAL BY ROW, GLOBAL} Set the table locality for a table in a multi-region database. No
SET (storage parameter) Set a storage parameter on a table. Yes

View schema changes

This schema change statement is registered as a job. You can view long-running jobs with SHOW JOBS.


Yes No
On this page

Yes No