-->

Sunday, March 9, 2014

How to use Unique Key Constraint on Column in SQL

How to use Unique Key Constraint on Column in SQL

Unique constraint is something like primary key constraint, which is used to make a record unique within all other records in sql database.

The unique constraint is used to enforce uniqueness on non-primary key columns. A primary key constrain column automatically includes a restriction for uniqueness. The unique constraint is similar to the primary key constraint except that it allows one NULL row.

Multiple unique constrains can be created on a table. The syntax of applying the unique constraint when creating table is:

CREATE TABLE table_Name
(
Col_name [CNTRAIN cstraint_name UNIQUE [CLUSTERED | NONCLUSTERED]
 Col_name [, col_name [, col_name [, …]]])
Col_name [, col_name [, col_name [, …]]]
)
Where
  • Constraint_name species the name of the constraint to created.
  • CLUSTERED | NONCLUSTERED are keywords that specify if a clustered or a nonclustered index is to be created for the unique constraint.
  • Col_name specifies the name of the column(s) on which the unique constraint is to be defined.
This constraint is also applied on columns as same as primary key constraint.

Primary Key Constraint
Foreign Key constraint

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved