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 key
mysql> 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> 

 

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2021-10-04
  • 2021-09-09
  • 2021-04-01
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2021-11-17
  • 2021-06-29
  • 2021-08-03
  • 2021-11-08
  • 2022-12-23
  • 2022-01-22
相关资源
相似解决方案