What is the difference between primary key and unique constraints?

A primary key is an attribute or column that can identify uniqueness in a row. Hence, it can be said that it is another name for a unique key. However, the default implementation in an SQL Server is different for a Primary Key and a Unique Key.

In a table, there can only be one primary key, however, there can be many unique constraints. A unique constraint can be any constraint. It need not be even be unique. It can also be a candidate key.

Additionally, primary key constraints are not nullable, whereas unique constraints may be nullable. When a unique constraint is created, the database automatically creates a unique index.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.