I have 2 tables: person and company.
I want to create a table address knowing that:
- a
personcan have zero, one or severaladdress - a
companycan have zero, one or severaladdress - the basic rows for
addressare the same forpersonandcompany
Solution 1
- Create a table
address(no foreign key) with all address rows (street, city...) - Create a
person_addresswith foreign keysaddress_idandperson_id - Create a
company_addresswith foreign keysaddress_idandcompany_id
=> A person and company can share the same address (good) and no duplication (good)
=> A bit cumbersome: I frist have to create adress then person/company_address
Solution 2
- Create a table
person_adresswith foreign keyperson_idand all address rows - Create a table
company_adresswith foreign keycompany_idand all address rows again
=> Rows for address info are defined twice
Solution 3?
Is there a way to create an unique table adress which could refer to either a person OR a company?