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