ALTER TABLE to add a composite primary key

前端 未结 6 1194
广开言路
广开言路 2020-11-28 01:19

I have a table called provider. I have three columns called person, place, thing. There can be duplicate persons, duplica

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 02:03

    You may simply want a UNIQUE CONSTRAINT. Especially if you already have a surrogate key. (example of an already existing surrogate key would be a single column that is an AUTO_INCREMENT )

    Below is the sql code for a Unique Constraint

    ALTER TABLE `MyDatabase`.`Provider`
        ADD CONSTRAINT CK_Per_Place_Thing_Unique UNIQUE (person,place,thing)
    ;
    

提交回复
热议问题