Adding and dropping columns

To add columns to existing tables, or to drop columns from existing tables, use the ALTER TABLE statement with the ADD COLUMN or DROP COLUMN clause. The table must not be a typed table.

About this task

For all existing rows in the table, the value of the new column is set to its default value. The new column is the last column of the table; that is, if initially there are n columns, the added column is column n+1. Adding the new column must not make the total byte count of all columns exceed the row size limit.

Procedure

  • To add a column, issue the ALTER TABLE statement with the ADD COLUMN clause.
    For example:
        ALTER TABLE SALES
          ADD COLUMN SOLD_QTY
          SMALLINT NOT NULL DEFAULT 0
  • To delete or drop a column, issue the ALTER TABLE statement with the DROP COLUMN clause.
    For example:
        ALTER TABLE SALES
          DROP COLUMN SOLD_QTY