What is the difference between primary key and unique key?

PointPrimary keyUnique key
NULL allowedNoYes (it allows NULL values)
How many per tableOneMany
PurposeIdentifies each rowStops duplicate values in a column, like email
CREATE TABLE users (
  id INT PRIMARY KEY,
  email VARCHAR(100) UNIQUE
);

See MySQL Constraints.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.