![]()
![]() ![]() ![]() ![]() ![]() ![]() ![]() Documentation Top ![]() Global Index ![]() Reference Manual ![]() ![]() ![]() Developer's Guide ![]() ![]() Tuning Cloudscape ![]() ![]() |
ALTER TABLE statementThe ALTER TABLE statement allows you to:
NEW: The ability to add or drop a default value for a column in the table and to override row-level locking for the table are new features in Version 3.0. Syntax
ColumnDefault
ALTER TABLE does not affect any view that references the table being altered. This includes views that have an * in their SELECT list. You must drop and re-create those views if you wish them to return the new columns. Adding ColumnsThe syntax for the ColumnDefinition for a new column is the same as for a column in a CREATE TABLE statement. This means that a column constraint can be placed on the new column within the ALTER TABLE ADD COLUMN statement. However, a column with a NOT NULL constraint can be added to an existing table only if the table is empty; otherwise, an exception is thrown when the ALTER TABLE statement is executed. (See Adding Constraints for the other limitations.) Just as in CREATE TABLE, if the column definition includes a primary key constraint, the column will be made non-nullable, so an exception is thrown if you attempt to add a primary key column to a table that is not empty. NOTE: If a table has an UPDATE trigger without an explicit column list, adding a column to that table in effect adds that column to the implicit update column list upon which the trigger is defined, and all references to transition variables are invalidated so that they pick up the new column. Adding ConstraintsALTER TABLE ADD CONSTRAINT adds a table-level constraint to an existing table. Any supported table-level constraint type can be added via ALTER TABLE. The following limitations exist on adding a constraint to an existing table: NOTE: When creating a primary key in a CREATE TABLE or ALTER TABLE ADD COLUMN statement, you automatically make all columns in a primary key non-nullable. ALTER TABLE ADD CONSTRAINT does not do this, so the columns it references when defining a primary key constraint must already be NOT NULL.
For information on the syntax of constraints, see CONSTRAINT clause. Use the syntax for table-level constraint when adding a constraint with the ADD TABLE ADD CONSTRAINT syntax. Dropping ConstraintsALTER TABLE DROP CONSTRAINT drops a constraint on an existing table. To drop an unnamed constraint, you must specify the generated constraint name stored in SYS.SYSCONSTRAINTS as a delimited identifier. Dropping a primary key, unique, or foreign key constraint drops its backing index. When you drop a primary key or unique constraint and there may be foreign key constraints referencing that primary key or unique constraint, you have two options:
Changing the Lock Granularity for the TableThe SET LOCKING clause allows you to override row-level locking for the specific table, if your system is set for row-level locking. (If your system is set for table-level locking, you cannot change the locking granularity to row-level locking, although Cloudscape allows you to use the SET LOCKING clause in such a situation without throwing an exception.) To override row-level locking for the specific table, set locking for the table to TABLE. If you created the table with table-level locking granularity, you can change locking back to ROW with the SET LOCKING clause in the ALTER TABLE statement. For information about why this is sometimes useful, see About the Optimizers Selection of Lock Granularity in Tuning Cloudscape. Adding or Dropping DefaultsYou can specify a default value for a column. A default value is the value that is inserted into a column if no other value is specified. If not explicitly specified, the default value of a column is NULL. If you add a default to a new column, existing rows in the table gain the default value in the new column. If you add a default to an existing column, existing rows in the table do not gain the default value in the new column. To drop a default, set the default value to NULL. Doing so does not affect the values of the column for existing rows. For more information about defaults, see CREATE TABLE statement. Examples
Dependency SystemAn ALTER TABLE statement causes all statements that are dependent on the table being altered to be recompiled before their next execution. ALTER TABLE is not allowed if there are any open cursors that reference the table being altered. | ||
![]() ![]() ![]() ![]() ![]() ![]() | ![]() ![]() Cloudscape Version 3.0 ![]() For technical support, go to: www.cloudscape.com and click Support. Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved. |