Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top