What is differen between old value and new value in trigger in mysql
What is differen between old value and new value in trigger in mysql
If we have a variable called "amount" and for example we use it in a trigger. We will have two variants of that variable ("NEW.amount", "OLD.amount"). These variants refer to the value BEFORE (OLD) and AFTER (NEW) of the trigger. So you can use the different values. I clarify that in an insert there is no OLD value and that in a delete there is no NEW value. An example is the following:
mysql> CREATE TRIGGER ins_transaction BEFORE INSERT ON account
FOR EACH ROW PRECEDES ins_sum
SET
@deposits = @deposits + IF(NEW.amount>0,NEW.amount,0),
@withdrawals = @withdrawals + IF(NEW.amount<0,-NEW.amount,0);
More information: https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html