Trigger Syntax and Examples @withdrawals = @withdrawals + IF(NEW.amount<0,-NEW.amount,0); Query OK, 0 rows affected (0.01 sec) This trigger,  ins_transaction , is similar to  ins_sum  but accumulates deposits and withdrawals separately. It has a  PRECEDES  clause that causes it to activate before  ins_sum ; without that clause, it would activate after  ins_sum  because it is created after  ins_sum . Within the trigger body, the  OLD  and  NEW  keywords enable you to access columns in the rows affected by a trigger.  OLD  and  NEW  are MySQL extensions to triggers; they are not case-sensitive. In an  INSERT  trigger, only  NEW. col_name  can be used; there is no old row. In a  DELETE  trigger, only OLD. col_name  can be used; there is no new row. In an  UPDATE  trigger, you can use  OLD. col_name  to refer to the columns of a row before it is updated and  NEW. col_name  to refer to the columns of the row after it is updated. A column named with  OLD  is read only. You can refer to it (if you have the  SELECT  privilege), but not modify it. You can refer to a column named with  NEW  if you have the  SELECT  privilege for it. In a  BEFORE trigger, you can also change its value with  SET NEW. col_name  =  value  if you have the  UPDATE privilege for it. This means you can use a trigger to modify the values to be inserted into a new row or used to update a row. (Such a  SET  statement has no effect in an  AFTER  trigger because the row change has already occurred.) In a  BEFORE  trigger, the  NEW  value for an  AUTO_INCREMENT  column is 0, not the sequence number that is generated automatically when the new row actually is inserted. By using the  BEGIN ... END  construct, you can define a trigger that executes multiple statements. Within the  BEGIN  block, you also can use other syntax that is permitted within stored routines such as conditionals and loops. However, just as for stored routines, if you use the  mysql  program to define a trigger that executes multiple statements, it is necessary to redefine the  mysql  statement delimiter so that you can use the  ;  statement delimiter within the trigger definition. The following example illustrates these points. It defines an  UPDATE  trigger that checks the new value to be used for updating each row, and modifies the value to be within the range from 0 to 100. This must be a  BEFORE  trigger because the value must be checked before it is used to update the row: It can be easier to define a stored procedure separately and then invoke it from the trigger using a simple CALL  statement. This is also advantageous if you want to execute the same code from within several triggers. There are limitations on what can appear in statements that a trigger executes when activated: •The trigger cannot use statements that explicitly or implicitly begin or end a transaction, such as  START TRANSACTION ,  COMMIT , or  ROLLBACK . ( ROLLBACK to SAVEPOINT  is permitted because it does not end a transaction.). •The trigger cannot use the  CALL  statement to invoke stored procedures that return data to the client or that use dynamic SQL. (Stored procedures are permitted to return data to the trigger through  OUT  or INOUT  parameters.) 4734 mysql>  delimiter // mysql>  CREATE TRIGGER upd_check BEFORE UPDATE ON account FOR EACH ROW BEGIN IF NEW.amount < 0 THEN SET NEW.amount = 0; ELSEIF NEW.amount > 100 THEN SET NEW.amount = 100; END IF; END;// mysql>  delimiter ;