Database table design
I have two parent tables, A and B and a child table C which has a relationship with either A or B. How do I best express this?
The tables is something like this:
A: id, text
B: id, text
C: id, sub_text
Adding two columns, a_id, b_id being nullable on C seems like a waste as only one of them will be set. I could add two columns parent_id and parent_table_name, but I would like some sort of foreign key relationship where the child data is deleted, and then this wont work (I think).
2 comments · 100% upvoted · other discussions
Just curious, is there any good reason why A and B are seperate tables?