alter table

Description

Adds, changes or drops columns; adds, changes, or drops constraints; partitions or unpartitions an existing table; changes the locking scheme for an existing table; specifies ascending or descending index order when alter table is used to create referential integrity constraints that are based on indexes; specifies the ratio of filled pages to empty pages, to reduce storage fragmentation.

Syntax

alter table [database.[owner].]table_name 
 {add column_name datatype
    [default {constant_expression | user | null}]
 {identity | null | not null}
     | [[constraint constraint_name]
       {{unique | primary key}
   [clustered | nonclustered] [asc | desc]
   [with { { fillfactor = pct
                   | max_rows_per_page = num_rows }
                   , reservepagegap = num_pages }]
          [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 [asc | desc]
                [, column_name [asc | desc]...])
        [with { { fillfactor = pct
                | max_rows_per_page = num_rows}
                , reservepagegap = num_pages}]
        [on segment_name]
   | foreign key (column_name [{, column_name}...])
        references [[database.]owner.]ref_table
            [(ref_column [{, ref_column}...])]
    | check (search_condition)}

| drop {[column_name [, column_name]] |
	[constraint constraint_name]}

| modify column_name {[data_type] [null] | 
	[not null]] [, column_name]

| replace column_name
    default {constant_expression | user | null}

| partition number_of_partitions

| unpartition

| lock {allpages | datarows | datapages } }

| with exp_row_size = num_bytes

Usage

Usage


Server Class ASEnterprise

Component Integration Services forwards the following syntax to a server configured as class sql_server:

alter table [database.[owner].]table_name 
	{add column_name datatype [{identity | null}]
       {[, next_column]}...}
	| [drop column_name [, column_name]}
	| modify column_name [data_type] [NULL] | 
		[not null]] [, column_name]}

Server Class ASAnywhere


Server Class ASIQ

Handling of the alter table command by servers in this class is the same as for ASEnterprise servers.


Server Class sql_server


Server Class direct_connect


Server Class db2

The datatype specification contains DB2 datatypes that are mapped from Adaptive Server datatypes. The datatype conversions are shown in Table 3-3.

Table 3-3: DB2 datatype conversions for alter table

Adaptive Server Datatype

DB2 Datatype

binary(n)

char(n) for bit data, where n <= 254

bit

char(1)

char(n)

char(n), where n <= 254

datetime

timestamp

decimal(p, s)

decimal(p, s)

float

float

image

Not supported

int

int

money

float

nchar

char(n)

nvarchar

varchar(n)

numeric(p, s)

decimal(p, s)

real

real

smalldatetime

timestamp

smallint

smallint

smallmoney

float

tinyint

smallint

text

Not supported

unichar

varchar(n) for bit data

univarchar

varchar(n) for bit data

varbinary(n)

varchar(n) for bit data, where n <=254

varchar(n)

varchar(n), where n <= 254

See also

See Also

alter table in the Adaptive Server Reference Manual.