Foreign key on table A --> B, AND foreign key on table B --> A. How is this done?
Posted
by unclaimedbaggage
on Stack Overflow
See other posts from Stack Overflow
or by unclaimedbaggage
Published on 2010-05-21T10:29:35Z
Indexed on
2010/05/21
10:40 UTC
Read the original article
Hit count: 225
Hi,
I have two tables - 'business' and 'business_contacts'.
The business_contact table has a many-to-one relationship with the business table. Furthermore, each business has a 'primary contact' field - which I'd assume is a one-to-many relationship with the business_contacts table.
The problem, of course, is that this creates a catch-22 for data insertion. Since neither field can be null, I can't insert a business_contact until I have a corresponding business, but I can't insert a business until I have a corresponding business_contact.
If anyone could help me get my head around how mutual one-to-many relationships are supposed to be dealt with I'd be most appreciative.
(Project being done in MySQL if it makes any difference)
© Stack Overflow or respective owner