Previous
Topic:
Views |
Next
Topic: Dependencies Among Database Objects |
A constraint is a restriction on the possible values that can be inserted into or updated in a column or table. Constraints are used to maintain the data integrity of the database by ensuring the consistency and correctness of its stored data. SAND CDBMS supports the following constraints, enforced on one or more columns in a database table:
- NOT NULL disallows missing or NULL values in the column on which it is defined.
- UNIQUE disallows duplicate values in the column(s) on which it is defined.
- PRIMARY KEY requires that values in the participating column(s) be both UNIQUE and NOT NULL.
- FOREIGN KEY enforces referential integrity—the relationship between a referencing or dependent table and a referenced or parent table. The referential integrity rule requires that, for any value in the dependent column(s), there must exist a row in the parent table where the value of the dependent column(s) equal(s) the value of the corresponding column(s) in a UNIQUE or PRIMARY KEY of the parent table.
Constraints are defined when a table is created through a CREATE TABLE statement, or when the table structure is modified by an ALTER TABLE statement. Constraints can be discarded from a table by using the ALTER TABLE...DROP CONSTRAINT command.
Constraints are named like any other database object. User-specified constraint names, however, are optional. If the constraint is not given a name by the user when it is created, SAND CDBMS automatically generates a unique name for the constraint. It is recommended that users provide meaningful names for their constraints, as this will result in greater intelligibility of error messages issued when constraints are violated, and will make it easier to drop constraints (since this can only be done by specifying the constraint name).
Consult Other Topics: Constraints for further details about column and table constraints.