Difference between primary key and unique key in SQL Server

This SQL Server tutorial, we will discuss what is the difference between primary key and unique key in SQL server.

Difference between primary key and unique key in SQL Server

Now, let us understand the difference between primary key and unique key in SQL Server.

Primary key in SQL Server

  • A primary key is(Unique key+not null). Primary Key is a combination of Unique and NOT NULL Constraints so it can’t have duplicate values or any NUll.
  • There must be one primary key can be present inside a table.
  • It doesn’t support null values.
  • It doesn’t support duplicates.
  • The primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist.
  • By default, Primary Key will generate a Clustered Index.

Unique key in SQL Server

  • There may be more than one unique key can be present in a table.
  • It supports null values but only once.
  • But it doesn’t support duplicates like suppose inside column there are two null values then SQL Server internally gives some different values but values are not equal.
  • A unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.
  • By default, Unique Key will Generate Non-Clustered Index.

You may like following SQL Server tutorials:

Here, we learned what are the difference between primary key and unique key in SQL Server.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>