I have a scenario where i would need to add a unique constraint using columns from 2 different tables. I have 2 tables. The first table is like,
TABLE MODEL(
ID PRIMARY_KEY,
KEY
)
and the second table as,
TABLE OWNERS(
ID PRIMARY_KEY,
MODEL_ID FOREIGN_KEY REFERENCES MODEL.ID,
USER
)
My requirement is the combination of MODEL.KEY + OWNERS.USER
should be unique.
How can we achieve this?
Note: I'm using Postgres as database. There is no possibility of adding OWNERS.USER to MODEL table.