8. SQL Statements : CREATE TABLE : Constraints
 
Share this page                  
Constraints
To ensure that the contents of columns fulfill your database requirements, specify constraints.
Constraints are checked at the end of every statement that modifies the table. If the constraint is violated, an error is returned and the statement is aborted. If the statement is within a multi-statement transaction, the transaction is not aborted.
Note:  Constraints are not checked when adding rows to a table using the COPY statement.
Constraints can be specified for individual columns or for the entire table. For details, see Column-Level Constraints and Table-Level Constraints (see Column-Level Constraints and Table-Level Constraints).
The types of constraints are:
Unique constraint–Ensures that a value appears in a column only once. Unique constraints are specified using the UNIQUE option.
Check constraint–Ensures that the contents of a column fulfills user-specified criteria (for example, “salary >0”). Check constraints are specified using the CHECK option.
Referential constraint–Ensures that a value assigned to a column appears in a corresponding column in another table. Referential constraints are specified using the REFERENCES option.
Primary key constraint–Declares one or more columns for use in referential constraints in other tables. Primary keys must be unique.