| Home | Previous Lesson: Parent-Child Tables Data-Entry Next Lesson: DELETE Trigger On trans Table |
CREATE trigger tran_new_trig after insert on trans
REFERENCING NEW AS new_tran
FOR EACH ROW
BEGIN
If "new_tran"."tran_type" = 'R' Then
update "product_master"
set "product_master"."product_balance" =
"product_master"."product_balance" +
"new_tran"."tran_qty"
where "product_master"."product_no" =
"new_tran"."tran_item_no"
Elseif "new_tran"."tran_type" = 'T' Then
update "product_master"
set "product_master"."product_balance" =
"product_master"."product_balance" +
"new_tran"."tran_qty"
where "product_master"."product_no" =
"new_tran"."tran_item_no"
Elseif "new_tran"."tran_type" = 'I' Then
update "product_master"
set "product_master"."product_balance" =
"product_master"."product_balance" -
"new_tran"."tran_qty"
where "product_master"."product_no" =
"new_tran"."tran_item_no"
End If
END; |
Type the above code in the database administration painter and execute it. Do the same for the next two triggers. We don't want to go into details, because, it has just few simple SQL statements.
| Home | Previous Lesson: Parent-Child Tables Data-Entry Next Lesson: DELETE Trigger On trans Table |