2009-05-28 79 views
1

我很难找到在表中创建唯一依赖关系的文档,例如,有2列,每个可以有多个相似的值,但绝不会有2行,其中两列都有相同的值(在另一行)...如何在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 is just like row 3, and that combination should be unique. 

回答

3

听起来像是你只是想对有问题的列的唯一约束。在MySQL类似的:

ALTER TABLE MyTable ADD UNIQUE (colA, colB); 
+0

谢谢...我误解唯一限制一列,而不是组合的唯一性。 – 2009-05-28 18:00:02

相关问题