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.

schema enter image description here

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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -