简体   繁体   中英

SQL relationship between three tables

I am new to SQL and I would like to make a following relationships.

Suppose, there is a table widgets which contains information about some products and there is a table warehouses which contains names of warehouses.

widgets and warehouses are related through many-to-many relationship as a given product is available in many warehouses and a given warehouse can store many products.

Now, I want to store information about the number of each product in each warehouse.

Should I simply create a new table quantities and connect it with both warehouse and widgets ?

You can keep this information in the wigetWarehouses table, assuming that you have at most one row per widget/warehouse combination.

Note that you might have a separate table for inventory movements. That would be more akin to a transactions table than a many-to-many relationships between the two entities.

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