A check constraint designates a condition that must be met before data can be inserted into a column.
CHECK Clause: (1) |--CHECK--(--| Condition |-------)------------------------------|
During an insert or update, if a row returns false for any check constraint defined on a table, the database server returns an error. No error is returned, however, if a row returns NULL for a check constraint. In some cases, you might want to use both a check constraint and a NOT NULL constraint.
Check constraints are defined using search conditions. The search condition cannot contain user-defined routines, subqueries, aggregates, host variables, or rowids. In addition, the condition cannot contain the variant built-in functions CURRENT, USER, SITENAME, DBSERVERNAME, or TODAY.
The check constraint cannot include columns in different tables. When you are using the ADD or MODIFY clause, the check constraint cannot depend upon values in other columns of the same table.
The next example adds a new unit_price column to the items table and includes a check constraint to ensure that the entered value is greater than 0:
ALTER TABLE items ADD (unit_price MONEY (6,2) CHECK (unit_price > 0) )
To create a constraint that checks values in more than one column, use the ADD CONSTRAINT clause. The following example builds a constraint on the column that was added in the previous example. The check constraint now spans two columns in the table.
ALTER TABLE items ADD CONSTRAINT CHECK (unit_price < total_price)
Use the DROP clause to drop one or more columns from a table.
DROP Clause: .-,------. V | |--DROP--+-(----column-+--)-+-----------------------------------| '-column-----------'
Element | Description | Restrictions | Syntax |
---|---|---|---|
column | Name of column to be dropped | Must exist in the table. No fragment expression can reference column, and it cannot be the last column in the table. | Identifier,
p. Identifier |
You cannot issue an ALTER TABLE DROP statement that would drop every column from the table. At least one column must remain in the table.
You cannot drop a column that is part of a fragmentation strategy.
In Extended Parallel Server, you cannot use the DROP clause if the table has a dependent GK index.
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]