relational-database - (数据库设计 - 产品属性): What is better option for product attribute database design?

标签 relational-database entity-attribute-value database-design

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

选项1:1 table

products{
id
product_name
color
price
attribute_name1
attribute_value1
attribute_name2
attribute_value2
attribute_name3
attribute_value3
}

选项 2:3 table
products{
id
product_name
color
price
}

attribute{
id
name
value
}

products_attribute{
products_id
attribute_id
}

最佳答案

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

每个属性都应以列名命名。颜色、页面、衬衫尺寸、发布日期,应该是列名。

如果每种产品类型都有一组不同的属性,则还有其他解决方案。请参阅我对以下问题的回答:

  • Product table, many kinds of product, each product has many parameters详情。
  • 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?

  • 另请阅读这个故事:Bad CaRMa: Introducing Vision在您实现围绕名称-值对设计的数据库之前。

    关于relational-database - (数据库设计 - 产品属性): What is better option for product attribute database design?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2945045/

    相关文章:

    mysql - 从 mysql 到 mongodb - 设计集合

    database-design - 在运行时动态创建表

    mysql - 创建表时外键错误(errno 150)

    database - 6NF和历史属性数据

    java - Grails/GORM 动态查找器通过其关系 ID 而不是关系对象本身来获取域

    mysql group by 加入列太慢

    database-design - 3NF 与 BCNF : Example

    mysql - 如何对价格调节因素建模?

    Magento eav 实体设置失败 - 创建了一半表,其他表没有创建

    sql - 触发器以确保总和小于不同表中的值