Primary Key versus Unique Key
Recently, I was asked the difference between a primary key and a unique key and this seemed like a good topic for a blog post.
First of all, the primary key is the key that will uniquely identify the record and enforce entity integrity. By default this will create a clustered index on the column or columns selected. The unique key, like the primary key, will be unique, however it creates a non-clustered index by default. The unique key will also allow one NULL record where the primary key will not allow any.
In addition, there is only one primary key per table, whereas you can have multiple unique keys. Enjoy!
Posted on March 11, 2013, in SQL Schoolhouse and tagged Index. Bookmark the permalink. 1 Comment.
The question I’ve been asked in every single DBA interview I’ve ever, ever had.