Innodb中,自增长值的列必须是索引,同时必须是索引的第一个列。如果不是第一个列,数据库会报出异常
mysql> create table t_inc01( -> a int auto_increment, -> b int, -> key(b,a) -> ) engine=innodb;ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a keymysql> create table t_inc01( -> a int auto_increment, -> b int, -> key(a,b) -> )engine=innodb;Query OK, 0 rows affected (0.01 sec)mysql>
MyISAM引擎中没有这个问题
mysql> create table t_inc02( -> a int auto_increment, -> b int, -> key (b,a) -> )engine=myisam;Query OK, 0 rows affected (0.00 sec)mysql>