What is the difference between primary key and unique key ?
Thanks for reaching out!
Unique key means that the values within that column are unique. You can have 1, 2, 3 or more fields whose values are unique, and that’s why you can have 0, 1, 2, 3 or more unique keys.
Primary keys have another function – to uniquely identify each record in a table. You can have only one such column/field, and it will be your primary key.
Hence, it is logical that a primary key is a type of unique key itself. But there can be only one primary key (regardless of whether it has been composed of only one column, or of many columns), that identifies each record in a table uniquely.
So, you can think of a primary key as a unique key that has the task to uniquely identify each record in a table.
Also, primary and unique keys cannot share fields. Among the various constraints that could apply to a specific field, the primary key and the unique key constraint potentially are two exclusive options.
Hope this helps.