0 0
Read Time:41 Second
Primary Key
Unique Key
Primary Key can’t accept null values.
Unique key can accept only one null value.
By default, Primary key is clustered index
and data in the database table is physically
organized in the sequence of clustered index.
By default, Unique key is a unique non-clustered index.  
We can have only one Primary key in a table.
We can have more than one unique key in a table.        
Primary key can be made foreign key into      another table.
In SQL Server, Unique key can be made foreign key into another table.

Example:

Create table Student
(
StuId int primary key, —- Define Primary Key
StuName varchar(50) Not Null,
ContactNo int Unique — Define Unique Key
)
Previous post Types of Keys in SQL with Key Differences: Primary Key vs. Foreign Key, and More
Next post Different Types of SQL Keys?
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Close
0
Would love your thoughts, please comment.x
()
x
× How can I help you?