Interview Question of the Week #010 – What is the Difference Between Primary Key Constraints and Unique Key Constraints?

I often see people getting confused between Primary Key and Unique Key. I see where people get confused about the same. Let us discuss.

Question: “What is the Difference Between Primary Key Constraints and Unique Key Constraints?”

Answer: “Primary Key (PK) Constraints enforce uniqueness just like Unique Key (UK) Constraints, however, PK does not allow  NULL value where as UK allows one NULL value.”

Well, the answer is as simple as above statement. You can read more about this over here: Primary Key Constraints and Unique Key Constraints.

I am very sure after reading above statement there will be few readers, who is going to comment and write email that when we create Primary Key Constraint it also creates clustered index on that column but Unique Key Constraint does not create clustered index. Well, this is the specific (and default) behavior in SQL Server where clustered index is automatically created, however user can create Primary Key Constraint without creating a clustered index as well and you can read about this over here Primary Key and NonClustered Index in Simple Words.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
Previous Post
SQL SERVER – Using Buffer Pool Extension with In-Memory OLTP?
Next Post
SQL SERVER – How to Add User Across Databases

Related Posts

No results found

1 Comment. Leave new

  • Roman Rapido
    May 19, 2016 4:32 am

    How do I Create Custom Primary Key for Multi-user Point of sale application? I need to create custom PK because I want to export and import data to a main location, the source would be the store branches, I export from the Branches and Import on the main sql server

    Reply

Leave a Reply

Menu