문제

I need to do constraint witch dont let to insert this two row:

INSERT INTO table1
VALUES('LON','BUD',2000, SYSDATE);
INSERT INTO table1
VALUES('BUD','LON',2000, SYSDATE);

either

INSERT INTO table1
VALUES('LON','BUD',2000, SYSDATE);

so in my view LON , BUD is equal to BUD, LON

And if i need to insert for example: LON - BUD, BUD-LON, BUD-MAD... from an other table how can i check it before inserting it?

도움이 되었습니까?

해결책

You can do this with a function-based index:

create unique index table1_col1_col2 on table1(least(col1, col2), greatest(col1, col2));

Alternatively, you could add a constraint that col1 < col2 and create a unique index on col1, col2. You could enhance this by adding an insert/update trigger to swap the values when given in the "wrong" order.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top