How to design a product table for many kinds of product where each product has many parameters

后端 未结 4 2137
故里飘歌
故里飘歌 2020-11-22 01:08

I do not have much experience in table design. My goal is to create one or more product tables that meet the requirements below:

  • Support many kinds of produ

4条回答
  •  情话喂你
    2020-11-22 02:02

    If I use Class Table Inheritance meaning:

    one table for Products, storing attributes common to all product types. Then one table per product type, storing attributes specific to that product type. -Bill Karwin

    Which I like the best of Bill Karwin's Suggestions.. I can kind of foresee one drawback, which I will try to explain how to keep from becoming a problem.

    What contingency plan should I have in place when an attribute that is only common to 1 type, then becomes common to 2, then 3, etc?

    For example: (this is just an example, not my real issue)

    If we sell furniture, we might sell chairs, lamps, sofas, TVs, etc. The TV type might be the only type we carry that has a power consumption. So I would put the power_consumption attribute on the tv_type_table. But then we start to carry Home theater systems which also have a power_consumption property. OK its just one other product so I'll add this field to the stereo_type_table as well since that is probably easiest at this point. But over time as we start to carry more and more electronics, we realize that power_consumption is broad enough that it should be in the main_product_table. What should I do now?

    Add the field to the main_product_table. Write a script to loop through the electronics and put the correct value from each type_table to the main_product_table. Then drop that column from each type_table.

    Now If I was always using the same GetProductData class to interact with the database to pull the product info; then if any changes in code now need refactoring, they should be to that Class only.

提交回复
热议问题