TurboDB Engine Documentation
ALTER TABLE Command
Previous  Top  Next


Modifies columns and column types of an existing table.

ALTER TABLE table_reference DROP column_reference | ADD column_reference column_type [NOT NULL] | RENAME column_reference column_reference | MODIFY column_reference column_type [NOT NULL] ...

Description
The ALTER TABLE command enables you to modify the structure of an existing table. There are four different options:

Delete an existing column with DROP:
ALTER TABLE Orders DROP Destination
The column_reference must refer to an existing column. Note that Turbo SQL column names are case-sensitive.

Add a new column with ADD:
ALTER TABLE Orders ADD Date_of_delivery DATE
The name of the new column must not exist before.

Modify the name of an existing column with RENAME:
ALTER TABLE Orders RENAME Date_of_delivery DateOfDelivery
The first column_reference is the name of an existing column, the second is the new name of this column. Renaming a column keeps the data within the column intact.

Modify the column type of an existing column with MODIFY:
ALTER TABLE Orders MODIFY DateOfDelivery TIMESTAMP
The column_reference must refer to an existing column. You may change the column type to any one of the available column types. The column data is kept as far as possible.

Note
RENAME and MODIFY are proprietary extensions to SQL-92.

It is possible to combine multiple changes in any order within one single command:
ALTER TABLE Orders ADD Date_of_delivery DATE, DROP Destination, ADD DeliveryAddress CHAR(200), RENAME Customer CustomerRef