B.7 ALTER TABLE

This statement supports several different commands to change the structure of a table, including adding, deleting, moving, and renaming fields.

ALTER TABLE tablename TO tablename2 
ALTER TABLE tablename ADD fieldname fieldtype [BEFORE fieldname2] 
ALTER TABLE tablename DROP fieldname
ALTER TABLE tablename MOVE fieldname [BEFORE fieldname2]
ALTER TABLE tablename RENAME fieldname TO fieldname2

Parameters

tablename

The name of the table in which to make structural changes.

tablename2

A new name for an existing table. A table with the same name cannot already exist.

fieldname

The name of the column in the table to add, remove, or rename. In order to add a column, it cannot already exist.

fieldname2

The name of another column in the table. For the ADD and MOVE statements, the name must exist in the table. For the RENAME statement, the name cannot already exist.

fieldtype

The data type for the column. For more information about data types, see CREATE TABLE.

Return Values

None.

Remarks

The ALTER TABLE statement renames a table, adds a column, moves a column, renames a column, or deletes a field from a table.

A table must contain at least one field. Attempting to drop the last field in a table results in an error that returns the constant adErrIllegalOperation.

Tables cannot have duplicate field names.

An SQL statement cannot be longer than 2,048 characters. A longer statement causes an error.