mysql - sql 如何约束多列中所有值均不同?
伊谢尔伦
伊谢尔伦 2017-04-17 12:57:32
0
3
591

如有一表结构:

CREATE TABLE t1(
    c1 INT,
    c2 INT,
    c3 INT
);

我如何写约束使得对任何两行,第一行的 c1, c2, c3 中任何一个与第二行的 c1, c2, c3 的任何一个均不同,且每一行的 c1, c2, c3 彼此不同?

Update:
查了 stackexchange 人家表示 unique 约束写不了,不过可以写 check 解决~
看看童鞋们有没有好办法。。。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
Ty80

You can only write check with constraints

Ty80

I feel that this constraint may not be achieved.
If you think about it differently, you need to get the relevant rows and make a judgment when performing INSERT, UPDATE, and DELETE on the table.

左手右手慢动作

Another way of thinking: Put the multi-column values ​​to be stored into one column, add a unique constraint to this column, and add an additional attribute identifier for different purposes

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template