mysql> create table animals(
    -> grp enum('fish', 'mammal', 'bird') not null,
    -> id mediumint not null auto_increment,
    -> name char(30) not null,
    -> primary key(grp,id));
ERROR 1075 (42000): Incorrect table definition; there can be only one auto colum
n and it must be defined as a key

解决方案 »

  1.   

    CREATE TABLE animals(
         grp ENUM('fish', 'mammal', 'bird') NOT NULL,
         id MEDIUMINT NOT NULL AUTO_INCREMENT,
         NAME CHAR(30) NOT NULL,
         PRIMARY KEY(grp,id),KEY(id));
      

  2.   

    我的没问题mysql> create table animals(
        ->     grp enum('fish', 'mammal', 'bird') not null,
        ->     id mediumint not null auto_increment,
        ->     name char(30) not null,
        ->     primary key(grp,id));
    Query OK, 0 rows affected (0.02 sec)
      

  3.   

    语法上没有问题。 应该是MYSQL版本上的差异。
      

  4.   

    哈哈哈哈,你们都错了。mysql> create table animals(
        -> grp enum('fish', 'mammal', 'bird') not null,
        -> id mediumint not null auto_increment,
        -> name char(30) not null,
        -> primary key(grp,id)) 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 animals(
        -> grp enum('fish', 'mammal', 'bird') not null,
        -> id mediumint not null auto_increment,
        -> name char(30) not null,
        -> primary key(grp,id)) engine=myisam;
    Query OK, 0 rows affected (0.30 sec)现在知道为什么了吧?