I am designing a database for an inventory management application that will handle stock level tracking of items and checkout order submission and processing. so far, i got: an Item table
- item id
- desc
- initial stock level
- other relevant info
an order table with
- order id
- order date
- customer id
an order_detail table with
- order detail id
- order id
- item id
- quantity
i am tracking the stock level using a transactions table where each time an order is processed or the stock is replinished, a record is inserted into that table with a transaction type to indicate if it's an in or an out transaction. transactions_in_out
- transaction id
- item id
- transaction type (in/out)
- quantity
- individual price
my problem is that before processing the order and inserting an out transaction, i would like to check whether stock level is sufficient, and also activate low stock alerts after transaction is inserted( although that is a different sort of problem). as it stands the only way to do this is to recalculate the current stock level!! if my tables grow as planned, this will have horrible effects on performance . what is the easiest way of doing this?