如有一表结构:
CREATE TABLE t1(
c1 INT,
c2 INT,
c3 INT
);
我如何写约束使得对任何两行,第一行的 c1
, c2
, c3
中任何一个与第二行的 c1
, c2
, c3
的任何一个均不同,且每一行的 c1
, c2
, c3
彼此不同?
Update:
查了 stackexchange 人家表示 unique 约束写不了,不过可以写 check 解决~
看看童鞋们有没有好办法。。。
PHP中文网2017-04-17 12:59:32
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.
ringa_lee2017-04-17 12:59:32
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