如何通过销售商品更新数据库中的库存数量?

时间:2021-09-03 20:46:07

I have two tables Items and Transactions in sql database I want to process sale i.e whenever an item gets sold the number of items sold gets subtracted from the total quantity of stock from table Items and the transaction detail inserted into Transaction table.

我在sql数据库中有两个表项目和事务我想处理销售,即每当一个项目被出售时,销售的项目数量将从表项目的总库存数量和插入到交易表格中的交易细节中减去。

Right now i am using these queries to to get items detail from items table and insert into Transaction table but I am unable to reduce the stock on each item sold.

现在我正在使用这些查询从items表中获取项目详细信息并插入到Transaction表中,但我无法减少每个销售项目的库存。

String query = "Select item_code,item_name, item_price,stock From Items  where Item_name=?";
String query = "Insert into Transactions(transaction_code, transaction_date, item_code, item_name, quantity, item_price, total) values (?,?,?,?,?,?,?) ;";

1 个解决方案

#1


1  

You can use trigger query , i think this article can help you https://docs.oracle.com/database/122/JJDEV/calling-Java-from-database-triggers.htm

您可以使用触发器查询,我认为本文可以帮助您https://docs.oracle.com/database/122/JJDEV/calling-Java-from-database-triggers.htm

#1


1  

You can use trigger query , i think this article can help you https://docs.oracle.com/database/122/JJDEV/calling-Java-from-database-triggers.htm

您可以使用触发器查询,我认为本文可以帮助您https://docs.oracle.com/database/122/JJDEV/calling-Java-from-database-triggers.htm