I'm currently creating some sort of inventory system.
I have tbl1
where in I save the items. In tbl1
, I have column qty
or the available stock left.
tbl1:
id product qty
1 mouse 10
2 keyboard 15
3 monitor 8
I also have the table tbl2
where in I save all the transaction in issuing items. In this table there is issued_qty
.
tbl2
id requested_by product issued_qty
1 john mouse 2
My problem is how can I INSERT a row into tbl2
at the same time UPDATE the tbl1.qty (tbl1.qty - tbl2.issued_qty)
.
for example:
when I insert record in tbl2
in requested_by, product and qty_issued, I want the tbl1
to be automatically updated. since we issue 2 (qty) of mouse to John. the record of mouse in tbl1, should be automatically less to the no. of issued quantity in tbl2
My idea is to use TRIGGER
but unfortunately I have no success.. can you please help me with this one..
thanks.