SQL BASIC

DB2 SQL 102 DDL : ALTER TABLE


SQL ALTER TABLE statement gives options to change almost every thing in TABLE structure. Like Add, Drop or Change definition of column(s).

  1. The altered table may consist up to 8000 columns.

Adding a column

ALTER TABLE STUDENT ADD COLUMN CITY CHAR(10)

Deleting a column

ALTER TABLE DEPT DROP COLUMN NUMDEPT

Changing a column

When you change the data type of an existing column, the old and new attributes must be compatible.

ALTER TABLE EX1 ALTER COLUMN COL2 SET DATA TYPE VARCHAR(30) 

Multiple Actions in one statement

ALTER TABLE STUDENT
 ALTER COLUMN CITY SET DATA TYPE VARCHAR(100)
 ADD COLUMN STATE CHAR(2) 
 DROP COLUMN OLD_CITY ;

IBM i developer.

View Comments
There are currently no comments.