Differences between primary keys and clustered Indexes

Source: Internet
Author: User
Tags comparison table

Comparison between the two

Below is a simple comparison table

  Primary Key Clustered Index
Purpose Forced table entity integrity Sorts data rows for easy Query
Number of tables in a table A table has at most one primary key. A table can have at most one clustered index.
Can multiple fields be defined? One primary key can be defined by multiple fields One index can be defined by multiple fields.
     
Whether NULL data rows are allowed If the data in the data column to be created is null, a primary key cannot be created.
The specified primary key constraint column during table creation is implicitly converted to not null.
Columns that do not limit the creation of clustered indexes must not be null.
That is, the column data can be null.
See the last comparison.
Must the data be unique? Data must be unique Data can be unique or not unique. See the unique settings you have defined for this index.
(In this case, we need to look at the following comparison. Although your data columns may not be unique, the system will generate a unique column that you cannot see for you)
     
Created Logic When the database creates a primary key, it automatically creates a unique index.
If no clustered index exists in the table and the non-clustered index is not specified when the primary key is created, a unique clustered index is created when the primary key is created.
If the unique attribute is not used to create a clustered index, the database engine automatically adds a four-byte uniqueifier column to the table.
If necessary, the database engine automatically adds a uniqueifier value to the row to make each key unique. This column and column value are used internally and cannot be viewed or accessed by users.

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.