(数据库设计 - 产品属性):产品属性数据库设计有什么更好的选择? [英] (Database Design - products attributes): What is better option for product attribute database design?

查看:24
本文介绍了(数据库设计 - 产品属性):产品属性数据库设计有什么更好的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始接触数据库设计.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:

另外阅读这个故事:糟糕的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆