(数据库设计 - 产品属性):什么是产品属性数据库设计的更好选择?

Yos*_*sef 9 database-design relational-database entity-attribute-value

我是数据库设计的新手.对于cms的产品属性数据库设计有什么更好的选择?(请另外建议其他选项).

选项1:1表

products{
id
product_name
color
price
attribute_name1
attribute_value1
attribute_name2
attribute_value2
attribute_name3
attribute_value3
}
Run Code Online (Sandbox Code Playgroud)

选项2:3表

products{
id
product_name
color
price
}

attribute{
id
name
value
}

products_attribute{
products_id
attribute_id
}
Run Code Online (Sandbox Code Playgroud)

谢谢你,约瑟夫

Bil*_*win 25

您犯了数据库设计的常见错误,将名称存储在一列中,将值存储在另一列中.这不是关系数据库设计.

每个属性都应按列名命名.颜色,页面,衬衫尺寸,发布日期,应为列名.

如果每种产品类型都有一组不同的属性,那么还有其他解决方案.看我的答案:

阅读这个故事:Bad CaRMa:在您实现围绕名称 - 值对设计的数据库之前,先介绍Vision.