Creating Constraints¶
A constraint can be created at table creation using CREATE TABLE, or added to a table later using ALTER TABLE:
Single-column constraints can be created inline as part of the column definition.
Multi-column constraints must be created in a separate, i.e. out-of-line, clause that specifies the columns in the constraint.
To create a constraint, certain access control privileges must be granted on the role used to create the constraint. For more information, see the security details described in Additional Constraint Details.
Creating Constraints Inline¶
The following inline syntax can only be used for single-column constraints:
CREATE [OR REPLACE] TABLE <name> (<column_name> <column_type> [ <inline_constraint> ] , ... )
ALTER TABLE <name> ADD COLUMN <column_name> <column_type> [ <inline_constraint> ]
For inline_constraint
syntax details, see CREATE | ALTER TABLE … CONSTRAINT.
Creating Constraints Out-of-line¶
The following out-of-line syntax must be used for multi-column constraints, but can also be used for single-column constraints:
CREATE [OR REPLACE] TABLE <name> ( ... , [ <outofline_constraint> ], ... )
ALTER TABLE <name> ADD <outofline_constraint>
For outofline_constraint
syntax details, see CREATE | ALTER TABLE … CONSTRAINT.