Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中创建唯一的依赖关系?_Mysql - Fatal编程技术网

如何在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);

谢谢我误解了“唯一性”是指限制一列的唯一性,而不是组合。