I’m trying to create a constraint on table A to check if a set of records exists in a table B. I could use a foreign key, but the problem is that the data in the table B is non-unique.
Is there a way to create such a constraint without creating a trigger?
Edit: I can’t change table B structure.
One technique would be to use a materialised view (fast refresh on commit) to store the unique values of the referenced column, and constrain your table against that.
Attempts at using triggers to enforce integrity are generally doomed due to read consistency or locking issues.