EDIT 3 添加了设计 + 清理
每个基表都是满足某个语句的行。找到语句。
Customer is the rows satisfying: customer [CustomerId] named [CustomerName] lives at ...
Product is the rows satisfying: product [ProductId] is named [Productname] costing [ProductPrice]
OrderDetail is the rows satisfying: orderDetail [OrderDetailId] of order [OrderId] is quantity [quantity] of product [ProductId]
Order is the rows satisfying: customer [CustomerId] ordered [OrderId] on [dateOfOrder]
您想要 Bill 中的哪些行?我猜……
Bill is the rows satisfying:
Bill [BillId] is for order [OrderId] on [dateOfBill] ... ???
您可以通过使用订单来了解有关账单的一些信息。您必须确定除了它的日期和顺序之外,您还想知道关于账单的其他内容(例如写一个),然后确定哪些报表账单行满足(即完成“...”)直接为您提供该信息(与其日期)或间接(与其顺序一样)。
我问
除了账单的日期和顺序之外,您还想知道什么(例如写一个)
BillId
dateOfBill
OrderId
order OrderId's customer's CustomerId, CustomerName, CustomerAddress ...
order OrderId's dateOfOrder
for every orderDetailId's orderDetail whose orderID = OrderId
quantity, ProductId, ProductNam,e ProductPrice, (quantity * ProductPrice) as productProduct
sum(quantity * ProductPrice) as total
over every orderDetail with OrderDetailId = OrderId
我问
哪些报表账单行满足直接或间接为您提供该信息
你建议
对于账单表,我打算有以下字段
Bill BillId (PK) CustomerId (FK) OrderId (FK) dateOfBill
Bill 必须直接给我们一个 BillId、dateOfBill 和 OrderId;他们不在其他地方。但其他一切都可以间接获得。
Bill is the rows satisfying:
bill [BillId] is for order [OrderId] and was billed on [dateOfBill]
我提到语句的原因是:需要它们查询和确定FD、键、唯一性、Fks和其他约束 . (而不是使用一种模糊的直觉。)这在设计方法 ORM2、NIAM 和 FCO-IM 中是明确的。
我通过查找其行将满足的语句来确定上面的帐单的内容:
customer [CustomerId] named [CustomerName] at [CustomerAddress] ...
owes us $[total] for order [OrderId]
ordering [quantity] of product [ProductId] named [ProductName] @ price $[ProductPrice] = [productProduct]
as recorded in bill [BillId]
这是由为每个表给出的语句组成的语句,除了我需要一些还没有在任何表中的语句,即(因此)Bill 需要给出的东西。通过用它们的表替换语句,我们将获得其值是我们想要的行的查询。