| Home | Previous Lesson: DELETE Trigger On trans Table Next Lesson: An Introduction to Triggers |
CREATE trigger tran_upd_trig after update on trans
REFERENCING old AS old_tran new AS new_tran
FOR EACH ROW
BEGIN
If "old_tran"."tran_type" = 'R' Or
"old_tran"."tran_type" = 'T' Then
Update "product_master"
Set "product_master"."product_balance" =
"product_master"."product_balance" -
"old_tran"."tran_qty" + "new_tran"."tran_qty"
Where "product_master"."product_no" =
"old_tran"."tran_item_no"
Elseif "old_tran"."tran_type" = 'I' Then
Update "product_master"
Set "product_master"."product_balance" =
"product_master"."product_balance" +
"old_tran"."tran_qty" - "new_tran"."tran_qty"
Where "product_master"."product_no" =
"old_tran"."tran_item_no"
End If
END; |
Now is the right time to close database painter and run the application and test it. Check if product_master is properly updated or not.
| Home | Previous Lesson: DELETE Trigger On trans Table Next Lesson: An Introduction to Triggers |