alter table (core)

Adds new columns and constraints, changes or drops constraints, and partitions or unpartitions an existing table.

Syntax

Transact-SQL Syntax

alter table [database.[owner].]table_name
{add column_name datatype
[default {constant_expression | user | null}]
 {[{identity | null}]
 | [[constraint constraint_name]
 {{unique | primary key}
 [clustered | nonclustered]
 [with {fillfactor | max_rows_per_page} = x]
 [on segment_name]
 [references [[database.]owner.]ref_table
[(ref_column)]
 | check (search_condition)}]}...
 {[, next_column]}...
| add {[constraint constraint_name]
 {unique | primary key}
 [clustered | nonclustered]
 (column_name [{, column_name}...])
 [with {fillfactor | max_rows_per_page} = x]
 [on segment_name]
 | foreign key (column_name [{, column_name}...])
 references [[database.]owner.]ref_table
[(ref_column [{, ref_column}...])]
 | check (search_condition)}
| drop constraint constraint_name
| replace column_name
default {constant_expression | user | null}
| partition number_of_partitions
| unpartition}

ODBC Syntax

ALTER TABLE base_table_name
{ADD column_identifier datatype
|ADD(column_identifier datatype[,column_identifier datatype]...)
|DROP[COLUMN]column_identifier[CASCADE|RESTRICT]}

Parameters

Examples

Usage

  • Adaptive Server/CIS sends the alter table command to the DirectConnect server as a language event.

  • These are not supported:
    • add constraint

    • drop constraint

    • replace column name

    • partition | unpartition

  • Transformation adds parentheses when the add column option includes more than one column.