订单 SQL 树状数据库
![在此处输入图像描述][2]我正在开发一个数据库,它将创建一个三-层级结构。这个想法将如下所示:
- 第一级:
Order
表- 主键 -
订单 ID
- 主键 -
- 第二级:
OrderlineItemHeader
表- 主键 -
订单 ID
- 主键 -
OrderLineItemHeaderID
- 主键 -
- 第三级:
OrderLineItem
表- 主键 -
OrderLineItemHeaderID
- PrimaryKey -
OrderLineItemSequence
- 主键 -
问题是它不允许我在第二层和第三层之间创建外键(OrderlineItemHeader.OrderLineItemHeaderID
到 OrderLineItem.OrderLineItemHeaderId
)。我一直在阅读有关 Hierarchyid 数据类型的内容,但问题是它们将它们关联到同一个表上。我显示的是主要列,但每个表还有五到十列所需的更多信息。
我使用的是 SQL Server 2008,关联它的程序是 VB.NET 4。我无法添加图表的图像,因为我是该网站的新手。
以食品为例再次进行解释:
您向一家拥有美国所有餐馆的食品供应商下了一笔巨额订单。
下达的订单包含该庞大订单列表的一般信息。
OrderID, OrderNO , OrderDate
现在订单有很多不同类型的食物,这是第二层。
披萨、鸡肉、肉、鱼。
您每种订购 1000 个,并且需要知道什么时候发货。
因此,他们会向您提供这些信息,您需要向每个人展示他们要吃饭的时间。
因此,您将在周二通过空运收到 100 份披萨。下周将有 500 人通过水路抵达。其余的则在两周内通过陆路到达。
明天会有 500 份肉到货,但由于他们没有准备好更多,所以剩下的都延期交货。
因此,所有这些信息都需要放入 tablkes 中,因此出现了 3 层模型
![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
- Primary Key -
- 2nd Level:
OrderlineItemHeader
table- Primary Key -
OrderID
- Primary key -
OrderLineItemHeaderID
- Primary Key -
- 3rd Level :
OrderLineItem
table- PrimaryKey -
OrderLineItemHeaderID
- PrimaryKey -
OrderLineItemSequence
- PrimaryKey -
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这方面还有很多额外的工作,但这里有一个基于我们迄今为止讨论的基本概念:
编辑
基于讨论的第二个图表(保留旧的历史记录)
There is a lot of additional work that goes into this, but here is a basic concept based on our discussion so far:
EDIT
Second Diagram based on discussion (Keeping the older one for history)
在您原来的问题陈述中,您有:
为了创建 OrderLineHeader 的外键,必须包含完整的 PK,因此您需要:
但如果所有 ID 都是人工的,则更好的解决方案可能是:
In your original problem statement you have:
in order to create a foreign key to OrderLineHeader, it's complete PK must be included, so you need:
but if all the IDs are artificial than a better solution may be: