简体   繁体   English

正确创建表关系

[英]Creating table relationships correctly

I have a form for an invoice creation and my task is that I want a user to be able to limit a customer's selection of data from a database based on selections the user has previously made. 我有一个用于创建发票的表格,我的任务是希望用户能够基于用户先前所做的选择来限制客户从数据库中选择数据。

My constraints are that each company has access to all products but the price for the same product will be different for different companies. 我的约束是,每个公司都可以使用所有产品,但是同一产品的价格对于不同的公司将有所不同。 Also each product may come in different sizes, which will have different prices. 每个产品的尺寸也可能不同,价格也不同。

Need help understanding the logic behind creating the connections between these classes. 需要帮助来了解在这些类之间创建连接的逻辑。

For instance my entities: 例如我的实体:
Company (attributes: CustID, Name, ShipTo, SoldTo, City, State, ZipCode)

Product (attributes: UN, Name, Hazard, Packing Class, Grade, Weight, Unit Type)

Now each product can come in many sizes, and each size has many products associated with it. 现在,每种产品可以有多种尺寸,每种尺寸都有许多与之关联的产品。 So I created a junction table titled Type with attributes Size and UN and linked in the Product and Type table together. 因此,我创建了一个名为Type的联接表,该联接表具有SizeUN属性,并在Product和Type表中链接在一起。

Then I created another junction because each company could have the same product and each product could be sold to many companies, and titled it CustProduct with attributes CustID and UN and linked it to Product table and Company Table. 然后,我创建了另一个联结,因为每个公司可以拥有相同的产品,并且每个产品都可以出售给许多公司,并使用属性CustIDUN将其命名为CustProduct并将其链接到Product表和Company Table。

Now I'm getting confused, how and where do I create a relationship that will allow link a unique price to product with a determinable size sold to a specific Company ? 现在我越来越糊涂,怎么和我在哪里创建关系,将允许链接一个独特的价格product具有确定的size出售给特定的Company Banging my head on this. 敲我的头。

From what you're saying, here is what I think: 根据您的意思,这是我的想法:

  • Your "Company" and "Product" entities look fine. 您的“公司”和“产品”实体看起来不错。
  • The "Type" table should have the following attributes: UN, SizeID, SizeName (where the key is UN, SizeID) “类型”表应具有以下属性:UN,SizeID,SizeName(其中键为UN,SizeID)
  • The final junction "CustProduct" should not be between the Company and Product, but rather between the company and the type tables, with the following attributes: CustID, UN, SizeID, Price. 最终结点“ CustProduct”不应位于公司与产品之间,而应位于公司与类型表之间,并具有以下属性:CustID,UN,SizeID,Price。

This means that each company can specify the price for each size of each product. 这意味着每个公司都可以为每种产品的每种尺寸指定价格。

I hope that helps. 希望对您有所帮助。

在此处输入图片说明

There is a many to many relationship beetween Company and Product table. 公司和产品表之间存在多对多关系。 By doing that, every product has different sizes and prices depending on a specific company 这样,根据特定公司的不同,每种产品都有不同的尺寸和价格

I think you can achieve your goals by implementing this structure. 我认为您可以通过实现此结构来实现目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM