1 Answers
Primary Key vs Unique Key Constraints in SQL Server
In SQL Server, both Primary Key and Unique Key constraints are used to enforce uniqueness on columns in a table. However, there are some key differences between the two:
Primary Key Constraint:
- A Primary Key constraint uniquely identifies each record in a table and does not allow NULL values.
- There can be only one Primary Key constraint per table.
- Primary Key constraint automatically creates a Clustered Index on the column(s) specified.
Unique Key Constraint:
- A Unique Key constraint enforces uniqueness on a column or a set of columns, but it allows NULL values (except in the column(s) specified).
- There can be multiple Unique Key constraints per table.
- Unique Key constraint automatically creates a Non-Clustered Index on the column(s) specified.
In summary, the main difference between Primary Key and Unique Key constraints in SQL Server is that a Primary Key uniquely identifies each record and does not allow NULL values, while a Unique Key allows NULL values and enforces uniqueness on a column or set of columns.

Please login or Register to submit your answer