Similarities and differences between the auto_increment field of the InnoDB engine and the Auto_increment field of the MyISAM engine

Source: Internet
Author: User

1. The Auto_increment field of the InnoDB engine must be an index. If it is a composite index, it must be the first column of the combined index.

CREATE TABLE Autoincrement_demo_inno (ID1 int not NULL auto_increment, ID2 int. NOT NULL, name varchar (), IND Ex (ID1, ID2)) Engine=innodb

This must be index (ID1, ID2) and an error will occur if the ID1 is not placed in the first place. As soon as you insert a new column, the Auto_increment field is self-increasing.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7D/02/wKioL1bedGTDbtn7AAAPRC3EpwA011.png "title=" 8.PNG " alt= "Wkiol1bedgtdbtn7aaaprc3epwa011.png"/>

As can be seen from the above, the number of columns inserted ID1 the number of self-increment.


2. The Auto_increment field of the MyISAM engine must also be an index, but if it is a composite index, it may not be the first column of the combined index.

CREATE TABLE Autoincrement_demo_myisam (ID1 int not NULL auto_increment, ID2 int. NOT NULL, name varchar (ten), I Ndex (Id2, ID1)) Engine=myisam

Here if you write index (ID1, ID2) as above, auto_increment effect is the same as above. If you put Id2 in front, the Auto_increment field's self-increment will take place in the same ID2 column.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7D/05/wKiom1befxHAx44bAAAQBnpQhaE711.png "title=" 9.PNG " alt= "Wkiom1befxhax44baaaqbnpqhae711.png"/>

As can be seen from the above, the self-increment of ID1 will be carried out in the same situation as ID2. If the index has more than one column, see if the field in front of the Auto_increment field is the same as the self-increment.

This article is from the "Bronze Gong" blog, please be sure to keep this source http://jaeger.blog.51cto.com/11064196/1748809

Similarities and differences between the auto_increment field of the InnoDB engine and the Auto_increment field of the MyISAM engine

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.