简体   繁体   中英

How to store sales in groups of orders

For a purchase-scenario:

I have a table (PRODUCTS) that contain columns like NAME, TYPE, DEFAULTPRICE, ID and a table with sales (SALES) that contain columns like DATE, ID, PRICE, AMOUNT where ID in SALES is a foreign key to primary key ID in PRODUCTS. Very simple, not much to mess up there.

This works fine as long as you insert one row of whichever product (and how many) at what total price.

BUT - let's say I want to design this system to support "basket"-kind of shopping. Ie a user selects several items that are not the same product ID, but gets a single ORDER ID that contains all the products that were included in the order, the amount of each product, the total price, date etc.

How would one go about creating this? I was thinking maybe creating a table called "ORDERS" and link every row from SALES to an ID from ORDERS - but I'm not sure.

You would create a table called Orders for each order. It would have whatever information you want about the order.

You would then have a table for the products in each order. A common name is OrderLines . This would have an OrderId , linking it to the Orders table and a ProductId linking to the Products table.

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