ALTER TABLE Description Alters the schema of an existing table by adding new columns or modifying existing columns of the specified table. Syntax ALTER TABLE [ owner_name. ] table_name { ADD [ new_column_name column_type [ NULL | NOT NULL ] [DEFAULT default_value]
| (new_column_name column_type [ NULL | NOT NULL ][DEFAULT default_value], … )
| MODIFY (column_name [ new_column_type ] [NULL | NOT NULL][DEFAULT default_value] , … )
| DROP [ COLUMN ] { column_name | ( column_name , … ) }
| ADD [ CONSTRAINT new_constraint_name ] table_constraint | DROP CONSTRAINT constraint_name } ; table_constraint :: PRIMARY KEY ( column [, … ] )
| UNIQUE ( column [, … ] )
| FOREIGN KEY ( column [, … ] )
REFERENCES [ owner_name. ] table_name [ ( column [, … ] ) ]
| CHECK ( search_condition ) Notes
Examples To add columns to the tmp table: ISQL> ALTER TABLE tmp ADD mname CHAR(8) ; ISQL> ALTER TABLE tmp ADD (mname CHAR(8), nname CHAR(8)) ; To add table-level constraints, consider the table tmp consisting of integer fields, fld, fld1, fld2, and fld3.
ISQL> ALTER TABLE tmp ADD UNIQUE(fld) ;
ISQL> ALTER TABLE tmp ADD primary key(fld1) ;
ISQL> ALTER TABLE tmp ADD constraint fri_cns foreign key(fld2) ;
ISQL> ALTER TABLE tmp ADD constraint chk_cns (fld2 > 10) ; Authorization The user executing this statement must have any of the following privileges:
|
|||||||||