The difference between primary key and unique key

Source: Internet
Author: User

Primary Key: primary key constraint

Unique key: unique key constraint

Similarities: Unique, neither value nor repetition

Differences:

1. A table can have only one primary key constraint, but multiple unique key constraints;

2. The primary key constraint can be composed of one or more keys, and the unique key constraint only applies to one key;

3. The field value of the primary key cannot be blank, and the field value of the unique key can be blank.

 

The primary key is essentially a constraint and the value is not empty. Only one table can be created to check data correctness;
The unique index is essentially an index, and the value can be empty. A table can be created with more than one index, which aims to optimize data query;

 

The difference between primary key and unique key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.