MySQL: Grouped primary key with InnoDB

后端 未结 2 498
长情又很酷
长情又很酷 2021-01-24 02:14

Is there an equivalent to a grouped primary key using an InnoDB MySQL database and allowing auto-increment on the second key?

What I am trying to implement is a table to

2条回答
  •  死守一世寂寞
    2021-01-24 02:55

    there can be only one auto column and it must be defined as a key. check this

    
    CREATE TABLE images (
       parent_id INT(11) NOT NULL,
       image_id INT(11) Not Null  AUTO_INCREMENT, 
       source_url VARCHAR(255) NOT NULL,
       caption VARCHAR(255) NOT NULL,
    
       key(image_id),                          -- add as a key       
       PRIMARY KEY(parent_id, image_id)
    ) ENGINE = InnoDB;
    

提交回复
热议问题