I have a relation table in Mysql with 3 columns
- ID (Primary key and Auto Increment)
- Ref_id1 (Reference ID from table1)
- Ref_id2 (Reference ID from table1 also)
How can i forbid, in database level, any pair combination of Ref_id1 and Ref_id2 from reappearing.
EDIT:
For example: After i insert a row like this
id Ref_id1 Ref_id2
1 1 2
i want to forbid ANY other row with the same pair of Ref_id1 and Ref_id2 (which a UNIQUE INDEX can solve) AND any row with the reversed pair
Ref_id1 Ref_id2
2 1
PS. Sorry for the ugly coding, i'm new to the community and i can't use the tools correctly
EDIT 2:
My question is different from the duplicate proposed because i want to be able to restrict BOTH insertions
Pair1:
Ref_id1 Ref_id2
1 2
AND
Pair2:
Ref_id1 Ref_id2
2 1
AFTER my original insertion.
EDIT 3:
If this helps at all: Both Ref_id1 and Ref_id2 are foreign keys from the same column of a foreign table