CREATE TABLE. The Default constraint is managed through
The user must have the
CREATE privilege on the table.
||The name of the table containing the column you want to constrain.|
||The name of the constraint, which must be unique to its table and follow these identifier rules.|
||The Check, Foreign Keys, Unique constraint you want to add.
Adding/changing a Default constraint is done through
Adding/changing the table’s Primary Key is not supported through
Add the Unique Constraint
Adding the Unique constraint requires that all of a column’s values be distinct from one another (except for NULL values).
> ALTER TABLE orders ADD CONSTRAINT id_customer_unique UNIQUE (id, customer);
Add the Check Constraint
Adding the Check constraint requires that all of a column’s values evaluate to
TRUE for a Boolean expression.
> ALTER TABLE orders ADD CONSTRAINT total_0_check CHECK (total > 0);
Add the Foreign Key Constraint
Adding the Foreign Key constraint requires that all of a column’s values are equal to an existing value in the column it references.
> ALTER TABLE orders ADD CONSTRAINT customer_fk FOREIGN KEY (customer) REFERENCEs customers (id);