What is a good way to prevent a table with 2 columns, a (unique) and b, from having any record where column b is equal to any value in column a? This would be used for a table of corrections like this,
MR -> Mr
Prf. -> Prof.
MRs -> Mrs
I can see how it could be done with a trigger and a subquery assuming no concurrent activity but a more declarative approach would be preferable.
This is an example of what should be prevented,
Wing Commdr. -> Wing Cdr.
Wing Cdr. -> Wing Commander
Ideally the solution would work with concurrent inserts and updates.
You could use a materialized view to enforce your requirements (tested with 10.2.0.1).
The unique index will ensure that you can not have the same value in both columns (on two rows).
It will serialize during commit but only on the values of columns A and B (ie: in general it should not prevent concurrent disjoint activity).
The unicity will only be checked at COMMIT time and some tools don’t expect commit to fail and may behave inappropriately. Also when the COMMIT fails, the entire transaction is rolled back and you lose any uncommited changes (you can not “retry”).