Syntax:
ALTER TABLE [catalog-name.]table-name alteration-action alteration-action: RENAME TO new-table-name alteration-action: ADD [COLUMN] column-def[, column-def]* alteration-action: DROP [COLUMN] column-name[, column-name]* alteration-action: MODIFY [COLUMN] column-name new-type-def[, column-name new-type-def]* alteration-action: RENAME COLUMN existing-column-name TO new-column-name[, existing-column-name TO new-column-name]
The ALTER TABLE is used to change the properties of a table.
GDBase's version of the ALTER TABLE command allows the user to rename a table, add, remove and change the type of a new or existing column.
The RENAME TO clause is used to rename the table identified by table-name to new-table-name.
If the renamed table has triggers or indices, then these remain attached to the table after it has been renamed. However, if there are any view definitions, or statements executed by the triggers that refer to the renamed table then they are not automatically modified to use the new table name. If this is required the triggers or view definitions must be dropped and recreated manually with the new table name.
The ADD [COLUMN] clause is used to add a new column to an existing table. The new column is always appended to the end of the list of existing columns. The column-def specification may take any of the forms permissable in the CREATE TABLE statement, with the following restrictions:
the column may not have a PRIMARY KEY or UNIQUE constraint,
the column may not have a defined data type,
the default value for a column may not be specified.
The DROP [COLUMN] syntax is used to remove an existing column identified by column-name from the table. A column with an index or from a table with the CHECK constraint cannot be dropped. This clause does not cause the loss of triggers created on the table.
The MODIFY [COLUMN] syntax is used to change the type of an existing column identified by column-name to new-type-def. A column with an index can not be modified.
The RENAME COLUMN syntax is used to change the name of an existing column identified by existing-column-name to new-column-name. A column with an index or from a table with the CHECK constraint cannot be renamed.
It is possible to have a multiple of any one of ADD, DROP or MODIFY clauses in a single ALTER TABLE statement by separating them with commas. However, combining ADD, DROP or MODIFY clauses in one statement is forbidden. For example, to do multiple ADD operations in a single statement, one can use the following:
ALTER TABLE mytable ADD COLUMN name varchar, age int;