Home  >  Article  >  Database  >  What is the difference between MySQL PRIMARY KEY and UNIQUE constraints?

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

WBOY
WBOYforward
2023-08-24 17:57:071110browse

MySQL PRIMARY KEY 和 UNIQUE 约束有什么区别?

The following table will provide us the difference between PRIMARY KEY and UNIQUE constraints-

tr>
Primary Key

Unique constraint

1. A table can only create one primary key.

1. Multiple UNIQUE constraints can be added to a table.

#2. The primary key creates a clustered index by default.

2. UNIQUE constraints create non-clustered indexes by default.

#3. We cannot insert null values ​​in columns defined as PRIMARY KEY.

3. We can insert null values ​​in columns with UNIQUE constraints.

The above is the detailed content of What is the difference between MySQL PRIMARY KEY and UNIQUE constraints?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete