I'm designing a small database for a personal project, and one of the tables, call it table C
, needs to have a foreign key to one of two tables, call them A
and B
, differing by entry. What's the best way to implement this?
Ideas so far:
- Create the table with two nullable foreign key fields connecting to the two tables.
- Possibly with a trigger to reject inserts and updates that would result 0 or 2 of them being null.
- Two separate tables with identical data
- This breaks the rule about duplicating data.
What's a more elegant way of solving this problem?