Database Table Layout
In setting up a MySQL database, consider that I have a table of products (tblCar) named:
- Coupe
- Sedan
- Mini-van
- Truck
And a list of (1980's) accessories:
- Moon roof
- Chrome wheels
- Window Tint
And a list of of options:
- paint color
- interior finish
- interior color
- Blu-Ray player in-dash
Now, let's setup some ground rules:
- Coupe can choose from any accessory or option
- Sedan can choose from any accessory but provides no Blu-Ray option
- Mini-van has window tint as an accessory and can choose from all options
- Truck only has chrom开发者_Go百科e wheels, tint accessories and only paint options
I need a tblCar setup, that much is clear. But how do I manage a table of tblAccessories and tblOptions without duplicating the line items themselves. Let's pretend that I only want description information for accessories and options and not prices as those would surely be different for the car they were installed in.
Would this be a case for tblAccessoriesHelper that holds a list of values of carID and accessoryID where the two should meet or this there a better method?
You would have junction tables, that join the two together
tblCar
tblAccessories
tblOptions
tblCarAccessories
tblCarOptions
There is another naming convention that uses the prefix "jct" if you are naming tables using "tbl". I would have named the tables
Car
Accessory
Options
CarAccessory
CarOptions
(name tables using the singular form, but "options" is special, because "option" could be a reserved/special word in some DBMS)
精彩评论