购物车数据库结构
我一直在研究购物车的数据库结构,并注意到在存储订单详细信息时,产品信息会重复并再次存储在表中。我想知道这背后的原因是什么?这是我的意思的一个小例子:
产品表
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
因此,您可以看到产品名称和价格再次存储在订单详细信息表中。这是为什么呢?我能想到的唯一原因是下订单后产品详细信息可能会发生变化,这可能会造成混乱。这是正确的吗?
谢谢
保罗
I have been studying the database structure for shopping carts and notice that when storing order details the product information is repeated and stored again in the table. I was wondering what the reasoning behind this would be? Here is a small example of what i mean:
Product Table
product_id name desc price
1 product 1 This is product 1 27.00
Order Table
order_id customer id order_total
1 3 34.99
Order Details Table
order_details_id product_id product name price qty
1 1 product 1 27.00 1
So as you can see the product name and price are stored again in the order details table. Why is this? The only reason i can think of is because the product details may change after the order has been placed which may cause confusion. Is this correct?
Thanks
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
唯一原因
是的,这是您的产品价格频繁变化的
,因此您可以再创建一个表并存储产品详细信息,如下所示
产品更新表
和订单表将是
yes this is the only reason
your product price get change frequently
so you can create one more table and store detail of product as shown below
Product update table
and order table will be
这样做可能是出于性能原因,不必执行 JOIN,只需执行直接 SELECT 即可获取订单详细信息。
Its probably done for performance reasons, instead of having to do a JOIN, only a straight SELECT can be done to get order details.
您可以修改您的结构,
无需在 orderdetail 中获取产品名称及其价格,只需获取订单 id
并在订单表中添加一个字段product_id
You can modify your structure according
there is no need to take productname and its price in orderdetail just take order id
and in order table add one field product_id