如何建立3表customer_order_transaction关系? [英] How to build a 3-table customer_order_transaction relationship?

查看:132
本文介绍了如何建立3表customer_order_transaction关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3张桌子:



客户: CustomerId ,FName,LName

订单: OrderId CustomerId ,商品,价格

OrderTransaction: OrderId ,金额......



因此,客户&订单表(1对多)



我的问题是,如何正确关联 OrderTransaction 表?



我应该将OrderTransaction表与Orders表联系起来,并在两者之间建立一对多的关系吗?那么1交易可以有很多订单吗?



处理此问题的最佳方法是什么?



我尝试了什么:



我在网上发现了这个经典模式,这让我对如何去做有了解。但首先我想问你们你的建议是什么?经典架构

I have 3 tables:

Customers: CustomerId, FName, LName
Orders: OrderId, CustomerId, Item, Price
OrderTransaction: OrderId, Amount...

Thus, Customers & Orders table (1-to-many)

My question is, how can I correctly relate the OrderTransaction table?

Should I relate the OrderTransaction table to the Orders Table and make a 1-to-Many relationship between the two? So 1-transaction can have many orders?

What's the best way to handle this?

What I have tried:

I found this classical schema online which kind of gives me an idea of how to go about it. But first I wanted to ask you guys what your recommendation would be classical schema

推荐答案

假设每个Order都由一个或多个OrderTransaction对象组成,那么Orders与OrderTransaction有一对多的关系。



根据实际发票考虑:它有一个客户(可能有很多发票),并且包含客户当天订购的一件或多件商品。

So Customer - >(一对多) - >订单 - >(一对多)Item(或架构中的OrderTransaction)
Assuming that each Order is made up on one or more OrderTransaction objects, then Orders has a one-to-many relationship with OrderTransaction.

Think about it in terms of a physical invoice: It has a Customer (who may have many invoices) and consists on one or more items the customer has ordered that day.
So Customer ->(one to many) -> Order ->(one to many) Item (or OrderTransaction in your schema)


这篇关于如何建立3表customer_order_transaction关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆