13

image Many-to-Many Relationships

Using a foreign key to reference another table satisfies the one-to-one and one-to-many cases. Many-to-many is a little bit more difficult, unless you place foreign keys in both tables. There is a significant problem with this approach because you have introduced a cross-dependency that is hard to maintain.

A clever solution is to create a small table whose sole purpose is to join the two tables together. You place the foreign keys in that table and remove them from the main two tables being joined. Yes, it is that simple.

Figure 13 Many-to-many mapping

Get Developing Quality Metadata now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.