简体   繁体   中英

WPF, C#, SQL - Creating rows in a Database

I am creating a billing software. I have created a database having 4 tables.

  • Category_Master
  • Product_Master
  • Customer_Master
  • Order_Details .

I am confused at creating rows in Order_Details. The reason is that, if a customer purchases 10 different items, then each items ProductCode should also be added to the Order_Details table.

So the thing is that do i need to create rows for each and every products or is their any other way to represent all ProductCode in a single cell.

You need to create rows. Although there are alternatives that are technically possible, all of them are incredibly bad design and an uneducated hack at best.

I would recommend you to slit your Order_Details into two tables:

OrderProduct

OrderID | ProductCode


Order_Details

OrderID | OtherParameter


Each product of the order should be a new row in OrderProduct table. This structure will allow you to store order details separate from Products, connected with this order. The OrderProduct table would contain only links of your products with the orders in relation of many to many. Joining of these tables would allow you to make any required Select queries.

I would also suggest you to create one more table (Order_Products) to manage the products ordered under one order, So that you will be able to easily track the products ordered under one order. Managing multiple values using a single cell can be used if the multiple values are of a constant size, such as days of a week which can be managed by using a binary field, But in your case the number of products is a variable and so i prefer using another table for doing the same.

Thank you.

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