Active Members
TodayLast 7 Daysmore...


Resources » Articles/Knowledge Sharing » Computer & Technology

Difference between Primary Key and Unique Key


Posted Date:     Category: Computer & Technology    
Author: Member Level: Silver    Points: 10



 

Hi Friends,

Difference between Primary Key and Unique Key is a very key question and it is generally asked in interview and in exams as well. I have listed the difference between Primary Key and Unique key below:-

Primary Key

1) Can not contain NULL values, this is because when we create a primary key, the NOT NULL constraint is automatically created for the column(s) the primary key is set. Note:- Unique key constraint is also created automatically therefore Primary Key is a combination of Unique Key constraint and NOT NULL constraint.
2) We can have only one Primary Key per table.
3) Creates clustered index by Default. We can have only one clustered index.
4) Primary key is used to uniquely identify a row or record in a table. Primary key ensures that no duplicate rows exist in a table.

Unique Key

1) Can or can’t contain NULL values i.e. if we define unique key on a column which is not null , then this unique key can also be used as an alternate primary key functionality to identify unique rows in a table. Note: - The number of NULL values a column can contain depends on RDBMS we are using i.e. SQL Server and DB2 don’t allow more than one NULL values whereas in Oracle we can have more than one NULL value.
2) We can have more than one Unique Key per table
3) Creates non-clustered index by Default
4) Unique key constraint ensures that no two rows contain duplicate value in a column or field, but if it is used with NOT NULL column then this can also serve the purpose of Primary key or can be used as alternate primary key.

Hope this will help you in understanding the concept of Primary Key and Unique Key. If you still have some doubt or needs more information you are always welcome.

With Regards,
Arvind





Did you like this resource? Share it with your friends and show your love!





Responses to "Difference between Primary Key and Unique Key"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: DLR-Dynamic Language Runtime
    Previous Resource: Internet protocol
    Return to Resources
    Post New Resource
    Category: Computer & Technology


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Difference between Primary Key and Unique Key  .  Primary Key Vs Unique Key  .  
    Awards & Gifts
    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.