我应该只使用一张桌子吗?

发布于 2024-12-07 19:49:31 字数 577 浏览 0 评论 0原文

我有一个实体Order

订单包含日期、客户、处理订单的员工等信息。

现在订单还需要存储状态,即区分赢得的订单和丢失的订单。

这个想法是,客户可以向公司提交订单,但最终可能退出

(作为域名信息,订单不是商品。它是一家服务公司,试图与客户打交道,并就何时可以交付订单以及以什么价格等提供报价。因此,客户可能会找到更好的布尔加恩和备份以及停止公司的订购流程)。

该公司需要有关赢得订单和丢失订单的数据,赢得订单和丢失订单之间的区别只是几个属性,例如 ReasonLost 可能是 Price时间

我的问题是,Order 的最佳表示是什么?

我正在考虑使用单个表,并且仅将赢得的订单的 ReasonLost 设置为 null。

如果这些新实体的差异并不显着,那么为 WonOrderLostOrder 创建单独的表是否有意义?

对于这种情况,最好的模型是什么?

I have an entity Order.

The order has information on date, client, associate who handled order etc.

Now the order also needs to store a state i.e. differentiate between won orders and lost orders.

The idea is that a customer may submit an order to the company, but could eventually back out.

(As domain info, the order is not of items. It is a services company that tries to handle clients and makes offers on when they can deliver an order and at what price etc. So the customer may find a better burgain and back up and stop the ordering process from the company).

The company wants data on both won orders and lost orders and the difference between a won order and a lost order is just a couple of more attributes e.g. ReasonLost which could be Price or Time.

My question is, what would be the best representation of the Order?

I was thinking of using a single table and just have for the orders won, the ReasonLost as null.

Does it make sense to create separate tables for WonOrder and LostOrder if the difference of these new entities is not significant?

What would be the best model for this case?

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

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

发布评论

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

评论(2

一人独醉 2024-12-14 19:49:31

使用一张桌子。添加 OrderState 字段。

警告:如果您每天进行数百万笔交易,那么像这样的决策需要更多的关注和分析。

Use one table. Add an OrderState Field.

Caveat: If you are doing millions of transactions per day, then decisions like this need much more attention and analysis.

囚我心虐我身 2024-12-14 19:49:31

您可能会考虑另一种替代设计。在这种替代方案中,您保留第二个表来说明订单丢失原因,并将其与您的订单表作为可选的 1:1 关联。请注意,这实际上是超类型/子类型模式的一种实现,其中丢失顺序子类型具有一个附加属性。

它看起来像这样:

ERD

在以下任何情况下,此替代方案可能很有吸引力:

  • 您损失的订单很少。
  • 您的订单表不够宽,无法容纳足够长的订单丢失原因。
  • 您的订单丢失原因非常非常大(甚至是 BLOB)。
  • 您出于审美原因反对在订单表中保留订单丢失原因。

There is another alternative design that you might consider. In this alternative you keep a second table for the order lost reason and relate it to your order table as an optional 1:1. Note that this is effectively an implementation of a supertype/subtype pattern where the lost order subtype has one additional attribute.

It looks like this:

ERD

This alternative might be attractive under any of the following circumstances:

  • You lose very few orders.
  • Your order table isn't wide enough to hold a long enough lost order reason.
  • Your lost order reason is very, very big (even BLOB).
  • You have an aesthetic objection to maintaining a lost order reason in your order table.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文