订单 SQL 树状数据库

发布于 2024-12-15 02:14:08 字数 1199 浏览 2 评论 0原文

在此处输入图像描述![在此处输入图像描述][2]我正在开发一个数据库,它将创建一个三-层级结构。这个想法将如下所示:

  • 第一级:Order
    • 主键 - 订单 ID
  • 第二级:OrderlineItemHeader
    • 主键 - 订单 ID
    • 主键 - OrderLineItemHeaderID
  • 第三级:OrderLineItem
    • 主键 - OrderLineItemHeaderID
    • PrimaryKey - OrderLineItemSequence

问题是它不允许我在第二层和第三层之间创建外键(OrderlineItemHeader.OrderLineItemHeaderIDOrderLineItem.OrderLineItemHeaderId)。我一直在阅读有关 Hierarchyid 数据类型的内容,但问题是它们将它们关联到同一个表上。我显示的是主要列,但每个表还有五到十列所需的更多信息。

我使用的是 SQL Server 2008,关联它的程序是 VB.NET 4。我无法添加图表的图像,因为我是该网站的新手。

以食品为例再次进行解释:

您向一家拥有美国所有餐馆的食品供应商下了一笔巨额订单。

下达的订单包含该庞大订单列表的一般信息。

OrderID, OrderNO , OrderDate

现在订单有很多不同类型的食物,这是第二层。

披萨、鸡肉、肉、鱼。

您每种订购 1000 个,并且需要知道什么时候发货。

因此,他们会向您提供这些信息,您需要向每个人展示他们要吃饭的时间。

因此,您将在周二通过空运收到 100 份披萨。下周将有 500 人通过水路抵达。其余的则在两周内通过陆路到达。

明天会有 500 份肉到货,但由于他们没有准备好更多,所以剩下的都延期交货。

因此,所有这些信息都需要放入 tablkes 中,因此出现了 3 层模型

enter image description here![enter image description here][2]I am working on a database that will create a three-tier structure. The idea is going to look like this:

  • 1st level: Order table
    • Primary Key - OrderID
  • 2nd Level: OrderlineItemHeader table
    • Primary Key - OrderID
    • Primary key - OrderLineItemHeaderID
  • 3rd Level : OrderLineItem table
    • PrimaryKey - OrderLineItemHeaderID
    • PrimaryKey - OrderLineItemSequence

The problem is it doesn't let me make the foreign key between the second and third levels (OrderlineItemHeader.OrderLineItemHeaderID to OrderLineItem.OrderLineItemHeaderId). I've been reading about the hierarchyid data type but the problem is that they relate them on the same table. What I'm showing are the main columns, but each table has five to ten columns more of information needed.

I am using SQL Server 2008 and the program that will associate it will be VB.NET 4. I cant add an image of my diagram because I'm new to the website.

Going to Put the Explanation again With the Food Example:

You place a huge Order for a Food Providor who owns all the Restaraunts in the US.

The Order placed has general info for that one huge order list.

OrderID, OrderNO , OrderDate

Now that Order has Many different type of foods, which is the second level.

Pizza , Chicken, Meat, Fish .

You order 1000 of each and you need to know what is coming when.

So they give you that information and you need to show everyone is going to eat when they are going to eat.

So from Pizza youll have 100 coming on tuesday by air. 500 coming by water coming next week. and the rest by land in 2 weeks.

Meat has 500 coming tmorrow, but since they dont have more ready, its backordered for a future date the rest.

So all that info needs to be put in tablkes, hence the 3 tier model

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

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

发布评论

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

评论(2

两仪 2024-12-22 02:14:08

这方面还有很多额外的工作,但这里有一个基于我们迄今为止讨论的基本概念:

输入图像描述这里

编辑

基于讨论的第二个图表(保留旧的历史记录)

There is a lot of additional work that goes into this, but here is a basic concept based on our discussion so far:

enter image description here

EDIT

Second Diagram based on discussion (Keeping the older one for history)

enter image description here

多像笑话 2024-12-22 02:14:08

在您原来的问题陈述中,您有:

3rd Level : OrderLineItem table
PrimaryKey - OrderLineItemHeaderID
PrimaryKey - OrderLineItemSequence

为了创建 OrderLineHeader 的外键,必须包含完整的 PK,因此您需要:

3rd Level : OrderLineItem table
PrimaryKey - OrderID
PrimaryKey - OrderLineItemHeaderID
PrimaryKey - OrderLineItemSequence

但如果所有 ID 都是人工的,则更好的解决方案可能是:

1st level: Order table
Primary Key - OrderID

2nd Level: OrderlineItemHeader table
Primary Key - OrderLineItemHeaderID
Foreign Key - OrderID

3rd Level : OrderLineItem table
Primary Key - OrderLineItemID
Foreign Key - OrderLineItemHeaderID

In your original problem statement you have:

3rd Level : OrderLineItem table
PrimaryKey - OrderLineItemHeaderID
PrimaryKey - OrderLineItemSequence

in order to create a foreign key to OrderLineHeader, it's complete PK must be included, so you need:

3rd Level : OrderLineItem table
PrimaryKey - OrderID
PrimaryKey - OrderLineItemHeaderID
PrimaryKey - OrderLineItemSequence

but if all the IDs are artificial than a better solution may be:

1st level: Order table
Primary Key - OrderID

2nd Level: OrderlineItemHeader table
Primary Key - OrderLineItemHeaderID
Foreign Key - OrderID

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