MySQL Forums
Forum List  »  Triggers

Re: How I can make the trigger calculates the sum of a column for specific condition
Posted by: Peter Brawley
Date: October 04, 2020 11:19AM

debt_alert.salary_transaction_id references salary_transactions.salary_transaction_id, on insert to which there can thus be no existing referring debts, so all you need is ...

create trigger remaining_money_calc
after insert on salary_transaction for each row 
insert into debt_alerts set
  salary_transaction_id = NEW.salary_transaction_id,
  remaining_money = 0, 
  employee_id=NEW.employee_id;

In an update Trigger there could be a need to do such a sum; you'd condition it on ...

...where salary_transaction_id=NEW.salary_transaction_id...

A note on Trigger naming ... to facilitate maintenance, it's a good idea to adopt a naming convention and stick to it. My preference is table_name_operation_context, so if it's my Trigger, its name is something like t_ins_money.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: How I can make the trigger calculates the sum of a column for specific condition
603
October 04, 2020 11:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.