alter table

Description

Using a language command, alter table adds new columns to an existing table.

Syntax

alter table [database.[owner].]table_name
add column_name datatype {null | not null}[{, next_column}...]

Parameters

table_name

is the name of the table to be changed.

column_name

is the name of a column to be added.

datatype

is the datatype of the column. Use only system datatypes, except bit. Certain datatypes expect a length, n, in parentheses:

	datatype(n)
null | not null

specifies a null value if a user does not provide a value during an insertion and no default exists (for null), or that a user must provide a non-null value if no default exists (for not null).

next_column

indicates that you can include additional column definitions separated by commas, using the same syntax described for a column definition.

Examples

Example 1

This example adds the manager_name column to the publishers table. For each existing row in the table, a null value is assigned to the new column.

alter table publishers
add manager_name varchar(40) null

Usage