如何在mysql中创建唯一的依赖关系?
我很难找到在一个表中创建唯一依赖项的文档,例如,其中有两列,每个列可以有多个相似的值,但决不能有两行,其中两列的值相同(如在另一行中) 换句话说如何在mysql中创建唯一的依赖关系?,mysql,Mysql,我很难找到在一个表中创建唯一依赖项的文档,例如,其中有两列,每个列可以有多个相似的值,但决不能有两行,其中两列的值相同(如在另一行中) 换句话说 colA colB row1 1 2 //this is ok row2 1 3 //this is ok row3 2 2 //this is ok row4 2 2 //this would NOT be ok, because this i
colA colB
row1 1 2 //this is ok
row2 1 3 //this is ok
row3 2 2 //this is ok
row4 2 2 //this would NOT be ok, because this is just like row 3, and that combination should be unique.
听起来您只是想在相关列上设置一个唯一的约束。在MySQL中,类似于:
ALTER TABLE MyTable ADD UNIQUE (colA, colB);
谢谢我误解了“唯一性”是指限制一列的唯一性,而不是组合。