In Oracle, as I declare a unique restriction on a pair of values, And this is the inverse pair

I have a table that defines a rule between two options:

CREATE TABLE VARIANTCOMBINATIONRULE ( VARRECID0 NUMBER(10) NOT NULL, VARRECID1 NUMBER(10) NOT NULL, RULE NUMBER ); ALTER TABLE VARIANTCOMBINATIONRULE ADD ( CONSTRAINT VARIANTCOMBINATIONRULE_PK PRIMARY KEY (VARRECID0, VARRECID1)); 

How to create a restriction prohibiting "reverse pairs"? At the same time, I mean that if there is an entry for options 12 and 14, you should not allow a new entry for a pair with the opposite (14 and 12).

+6
source share
1 answer
 CREATE UNIQUE INDEX unique_cd0_cd1 ON VARIANTCOMBINATIONRULE (least(VARRECID0, VARRECID1), greatest(VARRECID0, VARRECID1)); 
+7
source

Source: https://habr.com/ru/post/898923/


All Articles