This article will show what exactly difference between primary
key and the unique in sql server.
In this I will share the information about primary key and unique key and then
define.
Some of my other articles are as follows: Using
IF Else Statements In SQL Stored Procedure, Get
Year, Month, Date From Date in SQL, SQL
Query To Drop or Delete All Table, View, Stored Procedure and Trigger,
Insert,
Update, Delete, Select, Drop and Create Table In Ms Sql Server Database Table,
How
to reset your lost sql sa password | Reset SQL Server sa password by Windows
Authentication.
Primary key:
- A primary key on a sql table is a field is uniquely identifies each record in a database table.
- Primary key column always contain values.
- Primary key column value cannot have NULL values.
- A table can have only one primary key, which may consist of single or multiple fields.
Unique Key:
- A unique key on a sql table is a field is uniquely identifies each record in a database table.
- Unique key column can have only one NULL value.
Difference between Primary Key and Unique Key
PRIMARY KEY
|
UNIQUE KEY
|
It have uniquely identifies values without null value
|
It have uniquely identifies values with only one null value
|
Table column can have only one Primary key in a table
|
Table column can have only one Unique key in a table.
|
By default primary key adds a clustered index
|
By default unique key adds a non-clustered index
|
Primary key can be made foreign key into another table.
|
Unique key can be made foreign key into another table in sql server.
|
0 comments:
Please let me know your view