I’m using a MySQL database.
In which situations should I create a unique key or a primary key?
Advertisement
Answer
Primary Key:
- There can only be one primary key constraint in a table
- In some DBMS it cannot be
NULL– e.g. MySQL addsNOT NULL - Primary Key is a unique key identifier of the record
Unique Key:
- Can be more than one unique key in one table
- Unique key can have
NULLvalues - It can be a candidate key
- Unique key can be
NULL; multiple rows can haveNULLvalues and therefore may not be considered “unique”