【问题标题】:Order Tables Schema Issue订单表架构问题
【发布时间】:2023-03-13 03:52:01
【问题描述】:
我有两个表 Order_Primary 和 Order_Complete 问题是当我要生成账单时,Order_Primary 表中的账单中可能有多个产品,因此它会为每个产品生成 OrderId,尽管它们来自同一个账单,现在我应该如何在 Order_Complete 表中关联所有这些 OrderId,因为同一产品会有多个 OrderId,但必须只有一个 BillNo
Order_Primary
OrderId(主键)
ProductId(外键)
CategoryId(外键)
数量
成本
EmployeeId(外键)
Order_Complete
BillNo(主键)
OrderId(外键)
日期
【问题讨论】:
标签:
sql
sql-server-2008
database-design
schema
【解决方案1】:
要获得所需的结果,您必须将数据结构更改为以下内容:
Product_Group(添加新表)
ProductId (Foreign Key)
ProductGroupId
ProductGroupId+ProductId (Primary Key)
Order_Primary
OrderId (Primary Key)
ProductGroupId
^(Now here with a ProductGroupId you will get a list of products(Multiple))
CategoryId (Foreign Key)
Quantity
Cost
EmployeeId (Foreign Key)
Order_Complete
BillNo (Primary Key)
OrderId (Foreign Key)
Date