数据库设计——这里有冗余吗?

发布于 2024-11-05 09:38:03 字数 280 浏览 3 评论 0原文

我有四个表:公司、产品、客户和销售。它们之间的关系如下:

  • 一家公司可以拥有多个产品
  • 一家公司可以拥有多个客户
  • 销售是产品和客户的子项。每条销售记录都涉及一种产品和一位客户。

我对您可以通过两条不同的路线从销售追溯到公司这一事实感到不安。这可能会出现数据完整性问题 - 如果产品路由说最终母公司是 A 公司,而客户路由说它是 B 公司怎么办?

对我来说,这听起来像是 SQL 反模式,但我可能是错的。我能做什么呢?

谢谢!

I have four tables: Companies, Products, Customers and Sales. They are related as follows:

  • One Company can have multiple Products
  • One Company can have multiple Customers
  • A Sale is a child of a Product and a Customer. Each Sale record refers back to one Product and one Customer.

I am feeling uneasy about the fact that you can trace back from the Sale to the Company via two different routes. This raises the potential for data integrity issues - what if the Products route says the ultimate parent is Company A, and the Customer route says it's Company B?

This sounds like a SQL-antipattern to me, but I could be wrong. What can I do about it?

Thanks!

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

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

发布评论

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

评论(1

戒ㄋ 2024-11-12 09:38:03

这取决于。你说:

一个公司可以拥有多个
客户

这是否意味着每个客户只能在一家公司购物?

如果不是,客户公司之间的关系不应该由他们购买的产品来定义吗?

这意味着删除 Customer 上的 fk_Company 字段(或等效字段)。

但是,如果关系是客户注册的公司,则情况有所不同。

在这种情况下,如果购买的产品客户“所属”的公司之间存在冲突,则不是真正的冲突- 冲突将发生在客户注册公司客户注册的公司之间刚刚购物at,即不是真正的冲突。

最终的问题是,客户公司之间的关系是什么 - 客户

  • 最后一次购物(冗余)
  • 通常在哪里购物(多余)
  • 首先购物(多余)
  • 注册(也许不多余)

It depends. You say:

One Company can have multiple
Customers

Does this mean that each Customer only shops at one Company?

If not, shouldn't the relationship between a Customer and a Company be defined by the Products they have purchased?

This would mean removing the fk_Company field (or equivalent) on the Customer.

However, if the relationship is instead the Company that the Customer registered at, this is different.

In that case, if there was a conflict between the Products bought and the Company the Customer "belongs to", it is not a real conflict - the conflict would be between the Company the Customer registered at, and the Company that the Customer has just shopped at, i.e. not a real conflict.

The ultimate question is, what is the relationship between a Customer and a Company - is it where the Customer

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