I have 2 tables: person
and company
.
I want to create a table address
knowing that:
- a
person
can have zero, one or severaladdress
- a
company
can have zero, one or severaladdress
- the basic rows for
address
are the same forperson
andcompany
Solution 1
- Create a table
address
(no foreign key) with all address rows (street, city...) - Create a
person_address
with foreign keysaddress_id
andperson_id
- Create a
company_address
with foreign keysaddress_id
andcompany_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_adress
with foreign keyperson_id
and all address rows - Create a table
company_adress
with foreign keycompany_id
and 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
?