sql - How to update table based on values in another table -
i wondering according below schema
how can keep inventory out-stock values updated according product qty values in orderdetail
table.
for example have below sample data
orderdetail
order-id product-id qty 1 1 5
inventory
inventory-id date product-id in-stock out-stock stock-left 1 1/1/2016 1 10 5 5
lets in order-detail table value of qty changed 1 how can changed 1 in inventory table.
you can use triggers propagate values
create trigger [dbo].[inventory_update] on [dbo].[orderdetail] update begin update inventory set outstock = inserted.qty inserted inventory.inventory-id = inserted.inventory-id end
Comments
Post a Comment