ALTER TABLE

The ALTER TABLE statement applies a schema change to a table.

Note:

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

Viewing schema changes

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

Subcommands

For information on using ALTER TABLE, see the documents for its relevant subcommands.

Tip:

New in v19.1: 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.

SubcommandDescriptionCan combine with other subcommands?
ADD COLUMNAdd columns to tables.Yes
ADD CONSTRAINTAdd constraints to columns.Yes
ALTER COLUMNChange or drop a column's DEFAULT constraint or drop the NOT NULL constraint.Yes
ALTER TYPEChange a column's data type.Yes
CONFIGURE ZONEConfigure replication zones for a table.No
DROP COLUMNRemove columns from tables.Yes
DROP CONSTRAINTRemove constraints from columns.Yes
EXPERIMENTAL_AUDITEnable per-table audit logs.Yes
PARTITION BYRepartition or unpartition a table with partitions (Enterprise-only).Yes
RENAME COLUMNChange the names of columns.Yes
RENAME CONSTRAINTChange constraints columns.Yes
RENAME TABLEChange the names of tables.No
SPLIT ATForce a key-value layer range split at the specified row in the table.No
VALIDATE CONSTRAINTCheck whether values in a column match a constraint on the column.Yes

Viewing schema changes

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

Was this page helpful?
YesNo