我的 table 有点像
从到远
------ ---- ----------
A B 100
B C 100
Z A 120
我需要向表中添加一个不允许插入的约束B A 100
或C B 100
或A Z 120
我有一个PRIMARY KEY (from, to)
和CONSTRAINT const_u UNIQUE (to, from)
,但无法正常工作。
编辑:
我也无法强行按字母顺序排列正确顺序,因为我无权访问插入逻辑
编辑#2:您可以添加B A 50吗? -不,你不能。从A到B或从B到A应该只有一个唯一的距离,但不能同时有两个唯一的距离。
最佳答案
create unique index on the_table (least(from,to), greatest(from,to));
如果表(A,B,100)中已经存在,将阻止添加(B,A,100)。
关于sql - Oracle SQL唯一约束A到B,B到A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15731227/