--- title: ALTER TABLE (Transact-SQL) description: ALTER TABLE modifies a table definition by altering, adding, or dropping columns and constraints. ALTER TABLE also reassigns and rebuilds partitions, or disables and enables constraints and triggers. author: markingmyname ms.author: maghan ms.reviewer: randolphwest ms.date: 07/05/2024 ms.service: sql ms.subservice: t-sql ms.topic: reference ms.custom: - ignite-2024 f1_keywords: - "WAIT_AT_LOW_PRIORITY" - "ABORT_AFTER_WAIT" - "ABORT_AFTER_WAIT_TSQL" - "ALTER_TABLE_TSQL" - "ALTER TABLE" - "WAIT_AT_LOW_PRIORITY_TSQL" - "ALTER_COLUMN_TSQL" helpviewer_keywords: - "columns [SQL Server], resizing" - "changing column size" - "MAXDOP index option, ALTER TABLE statement" - "table modifications [SQL Server], ALTER TABLE" - "ALTER TABLE statement" - "modifying tables" - "partitioned tables [SQL Server], lock escalation" - "resizing columns" - "removing columns" - "switching partitions" - "reassigning partitions" - "removing constraints" - "triggers [SQL Server], disabling" - "columns [SQL Server], adding" - "LOCK_ESCALATION option of ALTER TABLE" - "constraints [SQL Server], deleting" - "constraints [SQL Server], disabling" - "triggers [SQL Server], enabling" - "re-enabling constraints" - "index modifications [SQL Server]" - "disabling constraints" - "columns [SQL Server], removing" - "max degree of parallelism option" - "locking [SQL Server], tables" - "ONLINE option" - "disabling triggers" - "constraints [SQL Server], adding" - "deleting constraints" - "adding constraints" - "adding columns" - "SWITCH partitions" - "partitioned tables [SQL Server], switching" - "lock escalation [SQL Server], option of ALTER TABLE" - "constraints [SQL Server], enabling" - "dropping constraints" - "dropping columns" - "data retention policy" - "table changes [SQL Server]" dev_langs: - "TSQL" monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric" --- # ALTER TABLE (Transact-SQL) [!INCLUDE [sql-asdb-asdbmi-asa-pdw-fabricdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricdw.md)] Modifies a table definition by altering, adding, or dropping columns and constraints. ALTER TABLE also reassigns and rebuilds partitions, or disables and enables constraints and triggers. ::: moniker range="=fabric" > [!NOTE] > Currently, `ALTER TABLE` in Fabric Warehouse is only supported for constraints and adding nullable columns. See [Syntax for Warehouse in Fabric](#syntax-for-warehouse-in-fabric). ::: moniker-end > [!IMPORTANT] > The syntax for ALTER TABLE is different for disk-based tables and memory-optimized tables. Use the following links to take you directly to the appropriate syntax block for your table types and to the appropriate syntax examples: > > - Disk-based tables: > > - [Syntax](#syntax-for-disk-based-tables) > - [Examples](#Example_Top) > - Memory-optimized tables > > - [Syntax](#syntax-for-memory-optimized-tables) > - [Examples](../../relational-databases/in-memory-oltp/altering-memory-optimized-tables.md) For more information about the syntax conventions, see [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md). ## Syntax for disk-based tables ```syntaxsql 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 = ' mask_function ') ] } [ WITH ( ONLINE = ON | OFF ) ] | [ WITH { CHECK | NOCHECK } ] | ADD { | | | } [ ,...n ] | [ system_start_time_column_name datetime2 GENERATED ALWAYS AS ROW START [ HIDDEN ] [ NOT NULL ] [ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES] , system_end_time_column_name datetime2 GENERATED ALWAYS AS ROW END [ HIDDEN ] [ NOT NULL ][ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES] , start_transaction_id_column_name bigint GENERATED ALWAYS AS TRANSACTION_ID START [ HIDDEN ] NOT NULL [ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES], end_transaction_id_column_name bigint GENERATED ALWAYS AS TRANSACTION_ID END [ HIDDEN ] NULL [ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES], start_sequence_number_column_name bigint GENERATED ALWAYS AS SEQUENCE_NUMBER START [ HIDDEN ] NOT NULL [ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES], end_sequence_number_column_name bigint GENERATED ALWAYS AS SEQUENCE_NUMBER END [ HIDDEN ] NULL [ CONSTRAINT constraint_name ] DEFAULT constant_expression [WITH VALUES] ] PERIOD FOR SYSTEM_TIME ( system_start_time_column_name, system_end_time_column_name ) | DROP [ { [ CONSTRAINT ][ IF EXISTS ] { constraint_name [ WITH ( [ ,...n ] ) ] } [ ,...n ] | COLUMN [ IF EXISTS ] { column_name } [ ,...n ] | PERIOD FOR SYSTEM_TIME } [ ,...n ] | [ WITH { CHECK | NOCHECK } ] { CHECK | NOCHECK } CONSTRAINT { ALL | constraint_name [ ,...n ] } | { ENABLE | DISABLE } TRIGGER { ALL | trigger_name [ ,...n ] } | { ENABLE | DISABLE } CHANGE_TRACKING [ WITH ( TRACK_COLUMNS_UPDATED = { ON | OFF } ) ] | SWITCH [ PARTITION source_partition_number_expression ] TO target_table [ PARTITION target_partition_number_expression ] [ WITH ( ) ] | SET ( [ FILESTREAM_ON = { partition_scheme_name | filegroup | "default" | "NULL" } ] | SYSTEM_VERSIONING = { OFF | ON [ ( HISTORY_TABLE = schema_name . history_table_name [, DATA_CONSISTENCY_CHECK = { ON | OFF } ] [, HISTORY_RETENTION_PERIOD = { INFINITE | number {DAY | DAYS | WEEK | WEEKS | MONTH | MONTHS | YEAR | YEARS } } ] ) ] } | DATA_DELETION = { OFF | ON [( [ FILTER_COLUMN = column_name ] [, RETENTION_PERIOD = { INFINITE | number {DAY | DAYS | WEEK | WEEKS | MONTH | MONTHS | YEAR | YEARS }}] )] } | REBUILD [ [PARTITION = ALL] [ WITH ( [ ,...n ] ) ] | [ PARTITION = partition_number [ WITH ( [ ,...n ] ) ] ] ] | | | } [ ; ] -- ALTER TABLE options ::= column_set_name XML COLUMN_SET FOR ALL_SPARSE_COLUMNS ::= { MAXDOP = max_degree_of_parallelism | ONLINE = { ON | OFF } | MOVE TO { partition_scheme_name ( column_name ) | filegroup | "default" } } ::= { SET ( LOCK_ESCALATION = { AUTO | TABLE | DISABLE } ) } ::= { [ { ENABLE | DISABLE } FILETABLE_NAMESPACE ] [ SET ( FILETABLE_DIRECTORY = directory_name ) ] } ::= { SET ( REMOTE_DATA_ARCHIVE { = ON () | = OFF_WITHOUT_DATA_RECOVERY ( MIGRATION_STATE = PAUSED ) | ( [, ...n] ) } ) } ::= { [ FILTER_PREDICATE = { null | table_predicate_function } , ] MIGRATION_STATE = { OUTBOUND | INBOUND | PAUSED } } ::= { SORT_IN_TEMPDB = { ON | OFF } | MAXDOP = max_degree_of_parallelism | DATA_COMPRESSION = { NONE | ROW | PAGE | COLUMNSTORE | COLUMNSTORE_ARCHIVE} } | ONLINE = { ON [( ) ] | OFF } } ::= { WAIT_AT_LOW_PRIORITY ( MAX_DURATION =