On this page
Warning:
As of May 12, 2021, CockroachDB v19.2 is no longer supported. For more details, refer to the Release Support Policy.
The ALTER TABLE
statement applies a schema change to a table. For information on using ALTER TABLE
, see the pages for its relevant subcommands.
Note:
This 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 or drop a column's DEFAULT constraint or NOT NULL constraint. |
Yes |
CONFIGURE ZONE |
Configure replication zones for a table. | No |
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 |
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 |
SPLIT AT |
Force a range split at the specified row in the table. | No |
UNSPLIT AT |
New in v19.2: Remove a range split enforcement at a specified row in the table. | No |
VALIDATE CONSTRAINT |
Check 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
.