Syntax error What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?

What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?



The following table will provide us the differences between PRIMARY KEY and UNIQUE constraint −

PRIMARY KEY
UNIQUE Constraint
1. Only one Primary key can be created on a table.
1. More than one UNIQUE Constraints can be added to a table.
2. Primary key creates clustered index by default.
2. UNIQUE Constraint creates a non-clustered index by default.
3. We cannot insert null values in the column which is defined as PRIMARY KEY.
3. We can insert null values in the column having a UNIQUE constraint.


Updated on: 2020-06-19T13:31:07+05:30

665 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements