Mapping One Table Row To Another Table Multiple Rows
I have a question which i don't know if it's possible.
lets say i have 3 tables:
Offices: Id, Name
Contacts : id , first_name, last_name, email, office_id
Sites : id, ip_addr, dns_addr, name, office_id
let say i have 2 sites under the same office_id, but they have a different contacts. how can i map between one row of Sites to multiple rows in Contacts??
i'm not too fimiliar with db architcure, so maybe i orgenized my db tables 开发者_如何学Gowrong?
thanks in advance.
The current structure of your DB doesn't associate a Site
with a Contact
at all - both are related to the office
.
The easiest way to do what you are after would be to create a lookup table that associates a Contact.id
with a Site.id
.
The problem you will have with this is there will be no inherent integrity checks - you can associate a contact with a site that's not affiliated with the same office. The major benefit here is you can have multiple contacts per site, or multiple sites per contact.
精彩评论