I posted a week or so about a database structure that I am trying to build. I didn’t quite get into the complexity of it, so that’s why I’m reposting. In the example, I used a CD collection as an example.
I understand that I need a lookup table for say my genres or publishers. That’s not a big deal to manage.
But there are eight lookup tables in this project and some of the tables have 150 entries in them. As I understand what was suggested, I need a separate entry for CD and its permutations of data. So if I have say 20 entries on average in a lookup table, that’s 20 x 20 x 20 x 20 x 20 x 20 x 20 x 20 permutations per CD. Or am I misunderstanding? How can I effectively create a master table to pull in all of the data without have a separate row for each permutation. Do I need to write some more complex SQL to manage all of this?
Help!
A brief overview of linking tables in SQL using the CD example.
Each disc can only have 1 label. We create a table of labels that looks like this:
Then in the CD table we have the external reference to the Label
When we want to see the results we do a join… like this:
One to many.
Lets say you have a one to many relationship then you need a joining table (I believe this is where you were getting confused.)
Fist we have the artist table for all artist available (note there can be more data in the artist table — dob, home town… etc.
Then we create a joining table. This will join one CD to many artists. A CD can have one or more rows in this table representing each link to an artist on the CD.
Of course we need an ID for the CD for this to work.
In CD Table
Then to select a list of artists for a particular CD you say