May 15th, 2009

How do Constraints Work?, UNIQUE (Part 1 of 2)

Posted by admin in P. Table Creation

The UNIQUE constraint makes sure that a column or columns have no duplicate values.> A table can have zero, one, or many UNIQUE constraints. It uses the reserved word UNIQUE in the CREATE TABLE statement.

> A simple constraint (one column) can be defined as a column constraint or a table constraint. As a simple column constraint, UNIQUE is placed in the column definition.

> A composite constraint (multiple columns) can only be defined as a table constraint. As a table constraint, the UNIQUE definition has the column names specified.

> A UNIQUE column can forbid nulls with NOT NULL.

> General practice is to use a CONSTRAINT clause to explicitly name all constraints. This gives a constraint name to make maintenance easier.

Comments are closed.

Sorry, the comment form is closed at this time.