Consider the following table structure:
titles(titleID*, titleName)
platforms(platformID*, platformName)
products(platformID*, titleID*, releaseDate)
publishers(publisherID*, publisherName)
developers(developerID*, developerName)
products_publishers(platformID*, titleID*,publisherID*)
products_developers(platformID*, titleID*, developerID*)
The products table is a joiner table using two foreign keys of platformID and titleID. This is because some titles have the same attributes across different platforms. To avoid data repetition, I created the joiner table.
My question arises when I create a products_publishers table. Because one product can have several publishers, I have to create a joiner table made from three foreign keys. Is this best practice? My scenario could have me create a table with four such entries. I considered using a column to store this data in the products table and forgo the joiner table and publisher table, but intuitively this does not feel right.
Any thoughts?
Many thanks
This is quite normal and refer to as composite keys. Another common strategy I have seen is to also give the table a primary key (surrogate key) like all the other tables. Some of the reasons for doing:
your table has a primary key
on a single key compared to
composite keys joining
ORM, it is usually better supported and make your code easier and cleaner to deal with single key than multiples.
I personally think that two composite keys are workable, but once you have three or more, you should really consider introducing surrogate key. Which ever strategy you choose, you just need to be consistent with it in your data model.