I have a couple triggers that automatically update invoice data and set some statuses in the database.
However, it appears that if 2 Triggers have variables that are named the same, they get overwritten when one trigger performs an update the causes the other trigger to run.
My BEFORE INSERT trigger on my payments table sets the variable
SET @amountPaid = @totalPayments + NEW.amount
Sometimes the before insert on payments will trigger an update to the main record which fires my BEFORE UPDATE trigger which selects the total payments into
@amountPaid for it's own conditionals. However, at this point
0 from the this perspective because the insert on payments hasn't completed, but this isn't important. What's very odd is that the @amountPaid variable in the payments trigger is now 0.
So now I'm curious as to how scope works in MySQL?