编码购物车:当用户结帐时,我是否应该将每条产品数据复制到“订单产品”中?表保存其状态?

发布于 2024-09-19 01:54:03 字数 302 浏览 3 评论 0原文

我是否应该将整个产品以及所有相关数据克隆到另一个表中以供后代使用,从而有效地记录产品的当前状态,就像用户购买它时一样?

优点:

  • 该产品(如用户购买时所看到的那样)为后代保留并且从未改变。如果产品数据随时间发生变化,则不会改变原始订单信息。

缺点:

  • 增加了很多复杂性:
    • 数据库中还需要几个表。
    • 需要跟踪的类似架构。
  • 使用更多磁盘空间。

有没有人有一个聪明的解决方案来解决这个难题?

Should I clone the entire product along with all related data into another table for posterity, effectively logging the current state of the product, as it was when the user purchased it?

Pros:

  • The product (as the user saw it when it was purchased) is held for posterity and never changed. If the product data changes over time, it won't change the original order information.

Cons:

  • A lot of added complexity:
    • Several more tables required in the database.
    • Similar schema to keep track of.
  • More disk space used.

Does anyone have a clever solution to this conundrum?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

随风而去 2024-09-26 01:54:04

我建议克隆与订单相关的产品属性。例如,单价。产品的大部分属性都不属于订单的一部分。
哪些属性与订单相关取决于企业如何开展业务。

如果只是一些属性,您可以将它们直接克隆到订单详细信息记录(行)中,而无需创建另一个表来保存该数据。增加的复杂性是最小的。

这是我对交易处理的建议。另一方面,如果您正在构建用于长期分析的数据仓库,那么在产品维度表上保留版本是正确的方法。

那么,您将永远不会对产品维度进行更新。相反,当产品属性发生更改时,您可以在产品维度中插入一个新行来保存新值。新行将具有相同的产品密钥,但版本号不同。

I would suggest cloning the attributes of the product that are relevant to the order. For example, the unit price. Most of the attributes of the product are not part of the order.
Which attributes are relevant to the order depends on how the enterprise does business.

If it's just a few attributes, you can clone them directly into the order detail record (row) and not create another table to hold that data. The added complexity is minimal.

That's my suggestion for transaction processing. If, on the other hand you are building up a data warehouse for long term analysis, then keeping a version on the product dimension table is the right way to go.

Then, you would never do an update to the product dimension. Instead, when a product attribute changes, you would insert a new row into the product dimension to hold the new values. The new row would have the same product key, but a different version number.

丢了幸福的猪 2024-09-26 01:54:04

我建议在产品数据中添加“版本号”,并保留旧版本。这样,您就可以维护产品数据,无需添加更多表,并且可以在使用过多空间时选择稍后剔除旧产品和订单。

I would suggest adding a 'version number' to the product data, and keeping old versions. This way, you maintain the product data, don't add more tables, and have the option of culling old products and orders later if you are using up too much space.

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