There are plenty of examples of both associative table
and one foreign key
designs out there, but I can't find clear any explanation of when should each of them be preferred.
For example let's assume my database needs to store the following information about people: first name, last name, address. I have 2 options of implementing this:
Option 1: associative table
Table: person
+----+------------+-----------+
| id | first_name | last_name |
+----+------------+-----------+
Table: address
+----+---------+-------+------+-----+-----+
| id | country | state | city | zip | etc |
+----+---------+-------+------+-----+-----+
Table: join_person_address
+-----------+------------+
| person_id | address_id |
+-----------+------------+
(both columns are foreign keys)
Option 2: one foreign key (in this case in the address
table)
Table: person
+----+------------+-----------+
| id | first_name | last_name |
+----+------------+-----------+
Table: address
+----+---------+-------+------+-----+-----+-----------+
| id | country | state | city | zip | etc | person_id |
+----+---------+-------+------+-----+-----+-----------+
(person_id is a foreign key)
What I learned so far
Associative tables are always used for many-to-many relationships.
One foreign key design may create situations that don't make sense for the data model (as in the example above - making an address reference a person when the address is the person's property and not the other way around, and making the person reference the address limits it to referencing only one address).
One foreign key design can be sufficient for one-to-one and one-to-many relationships but sometimes it may become required to change some relationships unexpectedly, so using a single foreign key design can be risky.
Conclusion: always use associative tables unless you can guarantee that the type of relationship won't ever change AND using one foreign key makes sense for the data model. Or to stay on the safe side: always use associative tables unless there is a really good reason not to.
The question
Based on what should I decide which option to use? (not specifically for the person-address relationship, that's just an example)
And why? (what are the advantages and disadvantages)
Is what I learned so far correct or did I get this wrong?