简体   繁体   中英

C# inventory updating stock

I am building an app with a SQL Server database. I have a main table of products ( tblProducts ) with a column that holds the quantity in hand ( quantity ). Another table holds the orders ( tblOrders ) that come from the supplier.

When an order comes in, I add the order to my database ( tblOrders ) and then I edit tblProducts to add to the quantity column the new received product. As far, everything is good.

My question: after let's say 1 year of many many orders, with a lot of edits in quantity, do you guys, periodically check all orders to check if the quantity in main table tblProducts is correct? Or do I just assume that it is always correct?

What procedures do you use for updating this kind of database? Do you sum all orders every time when you need quantity in hand?

Thanks!

This is really up to how you want to implement it.

  • Trusting that the values will always check out (with adequate testing to ensure only stable code will see production) is the easiest and the fastest way, but might be vulnerable to data corruption, and thus, not that recommended.
  • Always summing up the orders is the safest way and correct way, but will become increasingly slower as the size of your tables grow. If this is not an issue for you, then this is the recommended option.
  • What I consider a good intermediate method is to have a separate tblProductLogs table which stores the stock of an item at a specific timestamp. You can sum the inventory at set periods (daily, hourly, up to you), and when you want to retrieve the current inventory stock you only need to sum the values that were registered after the last log entry for that item, saving you query time. This could be made more safe if update operations were disabled on the log table, since you won't need to modify the entries there. This is faster than the second option, and somewhat more stable than the first.

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