SQL Unique key with Example

Unique Key

Unique key is similar to primary key and does not allow duplicate values in the column. It has below differences in comparison of primary key:

  1. it allows one null value in the column.
  2. by default, it creates a nonclustered index on heap tables.

The unique key can be defined as a set of one or more fields/columns of a table that have the capability to uniquely identify a record in the database table.

We can have other fields also in a table beyond primary key which is also able to uniquely identify the record. It can accept only one null value and it cannot have duplicate values in it.

Read Also: