Primary Key of the InnoDB Storage engine table

Source: Internet
Author: User

Primary Key of the InnoDB Storage engine table

In the InnoDB Storage engine, tables are organized and stored in the order of primary keys. In an InnoDB Storage engine table, each table has a primary key. If the primary key is not explicitly defined during table creation, the InnoDB Storage engine selects or creates an index as follows:

  • First, check whether the table has a unique index (unique not null) that is not empty. If so, the column is the primary key;
  • If condition 1 is not met, the InnoDB Storage engine automatically creates a six-byte pointer (rowid column ).

When multiple non-empty and unique indexes exist in the table, InnoDB Storage engine selects the first non-empty index defined during table creation as the primary key.

Create table t_sample (
A int null,
B int not null,
C int not null,
Unique key (),
Unique key (c ),
Unique key (B)
);

Insert into t_sample select 1, 2, 3;
Insert into t_sample select 1, 4, 5;
Insert into t_sample select null, 9, 7;

Query the primary key:

Select t. *, t. _ rowid from t_sample t;

_ Rowid can display the table's primary key. It can be seen that although B and c are unique indexes, c is defined first, so InnoDB Storage engine regards it as the primary key.

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151174.htm

Related Article

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.