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:

 Col_name [, col_name [, col_name [, …]]])
Col_name [, col_name [, col_name [, …]]]
  • 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


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites