(Database Design - products attributes): What is better option for product attribute database design?

落花浮王杯 提交于 2019-11-29 20:12:40
Bill Karwin

You're making a common mistake of database design, storing name in one column and value in another column. This is not a relational database design.

Each attribute should be named by the column name. Color, pages, shirt size, publish date, should be column names.

If each product type has a distinct set of attributes, there are other solutions. See my answers to:

Also please read this story: Bad CaRMa: Introducing Vision before you implement a database designed around name-value pairs as you are doing.

Esmaile

i think that the best implementation for product attribute you can get is

Product_Tbl [
    ID
    Name
    more columns
]

Attribute_Tbl [
   ID
   Att_Name
]

Product_Attribute_Tbl [
    Product_ID
    Attribute_ID
    Value
]

if your products not have the same attributes you can use this structure

That depends on what do you want from your database. If all of your products are of the same type and have same attributes then you just need to do something like that:

products{id: integer, product_name: string, color: string, attribute_name1: string, attribute_name2: string...}. Attribute_name{} should a meaningful word, just like "color" (which is an attribute too).

This is now an old topic, but thought it might be interesting to think about how this has evolved (especially with more processing speed means performance can be gambled at times).

Have you ever considered storing each attribute as a separate item in table ... lets say table "2", where the key back to the product would be an id:

    Product (table 1)
{
    Product ID
    Product Name
}

    Tags (table 2)
{
    Tag ID
    Higher Level tag ID
    Description
    Value
    Product ID
}

And that this table would contain also a field called "higher level" so you could find the unique ID within this table of which attribute was created as a higher level for this specific product. That way you have something called "omnilevel tagging".

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!