mysql - 购物车数据库结构

标签 mysql shopping-cart

我一直在研究购物车的数据库结构,并注意到在存储订单详细信息时,产品信息会重复并再次存储在表中。我想知道这背后的原因是什么?这是我的意思的一个小例子:

产品表

product_id     name               desc         price
1            product 1    This is product 1    27.00

订单表

order_id   customer id     order_total
1             3               34.99

订单明细表

order_details_id    product_id       product name      price    qty
       1                1              product 1        27.00     1

如您所见,产品名称和价格再次存储在订单详细信息表中。为什么是这样?我能想到的唯一原因是因为产品详细信息在下订单后可能会发生变化,这可能会造成混淆。这是正确的吗?

谢谢

保罗

最佳答案

是的,这是唯一的原因

你的产品价格经常变动

这样您就可以再创建一个表并存储产品的详细信息,如下所示

产品更新表

id product_id     name               desc         price
1     1            product 1    This is product 1    27.00

订单表将是

order_details_id    product_Update_id  qty
       1                1               1

关于mysql - 购物车数据库结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4560625/

相关文章:

php - 如何向 Pinnacle 购物车添加新的支付网关

Laravel:构建 Controller 时契约(Contract)文件不可实例化

php - Zen cart : I would like to query from a specific category its products name, 价格、图片、描述和属性

MySql 更新表替换string1 string2

paypal - 使用 Umbraco 进行在线销售

php - Angularjs如何获取服务中$http响应返回的Json格式的解析数据

mysql - 无法让 DataImportHandler 在 Tomcat 中为 Solr 工作

jquery - 使用 jquery 删除拖放购物车的按钮

使用 GROUP BY 时 MySQL 查询速度慢

mysql - 将 () 算作某物