ALTER TABLE
adds/drops/alters columns and constraints, switches partitions, toggles system-versioning, rebuilds
What changes
- Input
- existing table definition and, for some actions, its rows
- Output or change
- table definition; rows may be rewritten
Syntax at a glance
ALTER TABLE { database_name.schema_name.table_name | schema_name.table_name | table_name } { ALTER COLUMN column_name { [ type_schema_name. ] type_name [ ( { precision [ , scale ] | max | xml_schema_collection } ) ] [ COLLATE collation_name ] [ NULL | NOT NULL ] [ SPARSE ] | { ADD | DROP } { ROWGUIDCOL | PERSISTED | NOT FOR REPLICATION | SPARSE | HIDDEN } | { ADD | DROP } MASKED [ WITH ( FUNCTION = ' ...
Work example
A table needs a planned column, constraint, index, or storage change.
Check row count, dependencies, lock duration, log growth, and rollback before scheduling the schema change.
Check your work The table definition matches the release and existing rows satisfy every new rule.
Open Microsoft Learn for full syntax, permissions, and details for your version.