What’s the difference between a primary key and a unique key?

Category: SQLWhat’s the difference between a primary key and a unique key?
Editor">Editor Staff asked 2 years ago

What’s the difference between a primary key and a unique key?

1 Answers
Editor">Editor Staff answered 2 years ago

The differences between the primary key and a unique key are:

  • The primary key is a column whose values uniquely identify every row in a table. Primary key values can never be reused. They create a clustered index on the column and cannot be null.
  • A Unique key is a column whose values also uniquely identify every row in a table but they create a non-clustered index by default and it allows one NULL only.