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:
- SQL Server stored procedure tutorial
- Difference between clustered and non clustered index SQL server
- Difference between primary key and foreign key in SQL server
- Delete and create a new log file with minimum size in SQL Server
- Enable remote connections for SQL Server
- Sequence in SQL server
- SQL Server joins tutorial
- SQL Server Functions Tutorial
- SQL DML and DDL commands
- How to Setting maximum memory in SQL server?
- Create Configure and Use SQL Server Database using Microsoft Azure
- How to create SQL Database in Microsoft Azure Portal
- Connect to Azure SQL database from management studio
Here, we learned what are the difference between primary key and unique key in SQL Server.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.