Define a unique primary key based on 2 columns

后端 未结 7 602
长情又很酷
长情又很酷 2021-01-31 02:52

I would like to define a unique key for records based on 2 columns : \'id\' and \'language\'

to let the user submits the following strings : id=1 language=en value=bl

7条回答
  •  死守一世寂寞
    2021-01-31 03:26

    Just like @rogal111 said, but if a primary key already exists then you'll want to do this

    ALTER TABLE sections DROP PRIMARY KEY, ADD PRIMARY KEY(id, workspace_id, section_key);
    

提交回复
热议问题