购物车数据库结构

发布于 2024-10-10 04:08:54 字数 627 浏览 0 评论 0原文

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

产品表

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半夏半凉 2024-10-17 04:08:54

唯一原因

是的,这是您的产品价格频繁变化的

,因此您可以再创建一个表并存储产品详细信息,如下所示

产品更新表

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

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

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

and order table will be

order_details_id    product_Update_id  qty
       1                1               1
演出会有结束 2024-10-17 04:08:54

这样做可能是出于性能原因,不必执行 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.

蝶…霜飞 2024-10-17 04:08:54

您可以修改您的结构,

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

order_id  product_id  customer id   order_total
1         1           3             34.99

order_details_id   order_id  qty
1                  1         1

无需在 orderdetail 中获取产品名称及其价格,只需获取订单 id
并在订单表中添加一个字段product_id

You can modify your structure according

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

order_id  product_id  customer id   order_total
1         1           3             34.99

order_details_id   order_id  qty
1                  1         1

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文