The six types of Oracle constraints
Quick reference of Oracle constraint types: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and REF.
An Oracle constraint enforces a rule that restricts the values allowed in the database. There are six types of constraints; all of them, except NOT NULL, can be declared in two ways (at column level or at table level).
| Type | Description |
|---|---|
NOT NULL |
If a column is declared NOT NULL, a value must be inserted into it. |
UNIQUE |
A UNIQUE column or set of columns prevents multiple rows from having the same value in those columns, but allows null values. |
PRIMARY KEY |
The combination of a NOT NULL constraint and a UNIQUE constraint: a single declaration satisfies both. |
FOREIGN KEY |
Requires values in one table to match values in another table. |
CHECK |
Restricts values based on a specified condition. |
REF |
Further describes the relationship between a REF column and the object it references. |
To list the constraints of a table, see the DBA_CONSTRAINTS, USER_CONSTRAINTS and ALL_CONSTRAINTS views.