Define what these terms mean first of all:
- A "superkey" is any set of attributes that, when combined, uniquely identifies the rows in the table.
- A minimum of 1 superkey is called a candidate key or simply a key .
- All keys in one table are logically equivalent, but for historical and practical reasons we select one of them and call it "primary" , and the rest - "alternate" .
So, each primary key is a key, but not every key is a primary. Each key is a super-key, but not every super-key is a key.
The restrictions that physically apply keys in the database are: PRIMARY KEY constraint (for the primary key) and UNIQUE constraint (for the alternate key). These restrictions should not be created on all super-keys, only on keys.
There is nothing unusual in the fact that in one table there are several keys, depending on the nature of your data. For example, a USER table may have a unique USER_ID and a unique USER_NAME. Since both of them must be unique in themselves, you must create 2 both keys, although only one of them is strictly required for identification.
1 That is, a superkey that will cease to be unique (and, therefore, will become a superkack) if any of the attributes has been removed from it.
2 Ie create a PRIMARY KEY or UNIQUE constraint.
source share