(数据库设计-产品属性):什么是产品属性数据库设计的更好选择? [英] (Database Design - products attributes): What is better option for product attribute database design?
问题描述
我是数据库设计的新手.什么是针对cms的产品属性数据库设计的更好选择?(请同时建议其他选择).
I new in database design. What is better option for product attribute database design for cms?(Please suggest other options also).
选项1:1张桌子
products{
id
product_name
color
price
attribute_name1
attribute_value1
attribute_name2
attribute_value2
attribute_name3
attribute_value3
}
选项2:3张桌子
products{
id
product_name
color
price
}
attribute{
id
name
value
}
products_attribute{
products_id
attribute_id
}
推荐答案
您在数据库设计中犯了一个常见错误,将名称存储在一个列中,将值存储在另一列中.这不是关系数据库设计.
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:
- Product table, many kinds of product, each product has many parameters for details.
- How do you model custom attributes of entities?
- Design question: Filterable attributes, SQL
- How to design a database schema to support tagging with categories?
- How to define structure in a tag-based organization?
也请读这个故事:错误的CaRMa:介绍视觉 ,然后再实现围绕名称-值对设计的数据库.
Also please read this story: Bad CaRMa: Introducing Vision before you implement a database designed around name-value pairs as you are doing.
这篇关于(数据库设计-产品属性):什么是产品属性数据库设计的更好选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!