简体   繁体   中英

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.

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.

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 ? 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)
  • 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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