Defining Composite Key with Auto Increment in MySQL

后端 未结 5 1457
心在旅途
心在旅途 2020-12-01 04:01

Scenario:

I have a table which references two foreign keys, and for each unique combination of these foreign keys, has its own auto_increment column

5条回答
  •  旧巷少年郎
    2020-12-01 04:22

    Just add key(sr_no) on auto-increment column:

    CREATE  TABLE `issue_log` (
     `sr_no` INT NOT NULL AUTO_INCREMENT ,
     `app_id` INT NOT NULL ,
     `test_id` INT NOT NULL ,
     `issue_name` VARCHAR(255) NOT NULL ,
      primary key (app_id, test_id,sr_no),
      key (`sr_no`)
    );
    

提交回复
热议问题