There can be only one auto column

前端 未结 4 1664
闹比i
闹比i 2020-12-13 03:29

How do I correct the error from MySQL \'you can only have one auto increment column\'.

CREATE TABLE book (
   id INT AUTO_INCREMENT NOT NULL,
   accepted_ter         


        
4条回答
  •  忘掉有多难
    2020-12-13 03:37

    Note also that "key" does not necessarily mean primary key. Something like this will work:

    CREATE TABLE book (
        isbn             BIGINT NOT NULL PRIMARY KEY,
        id               INT    NOT NULL AUTO_INCREMENT,
        accepted_terms   BIT(1) NOT NULL,
        accepted_privacy BIT(1) NOT NULL,
        INDEX(id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    

    This is a contrived example and probably not the best idea, but it can be very useful in certain cases.

提交回复
热议问题