In this article, I would like to discuss on one of the common but the most misleading topics in RDBMS. What is the difference between Primary Key and Unique Key?
By definition, Primary Key and Unique Key technically says about the same thing.
Unique Key(UK): It’s a column or group of columns that can identify a uniqueness in a row.
Primary Key(PK): It’s also a column or group of columns that can identify a uniqueness in a row.
So why there is two different terminology? Well I would like to compare these terminologies in the below table
| Primary Key | Unique Key |
|---|---|
| Can be only one Primary Key in a table | Can be more than one unique key in one table |
| By default Primary Key creates a Clustered index | By default Unique Key creates a Non-Clustered Index |
| In some DBMS it cannot be NULL – e.g. MySQL adds NOT NULL | It can be NULL |

Leave a comment