Trigger Syntax and Examples See also Section 25.8, “Restrictions on Stored Programs” . MySQL handles errors during trigger execution as follows: Triggers can contain direct references to tables by name, such as the trigger named  testref  shown in this example: CREATE TABLE test1(a1 INT); CREATE TABLE test2(a2 INT); CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY); CREATE TABLE test4( a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b4 INT DEFAULT 0 ); delimiter | CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BEGIN INSERT INTO test2 SET a2 = NEW.a1; DELETE FROM test3 WHERE a3 = NEW.a1; UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1; END; | delimiter ; INSERT INTO test3 (a3) VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); INSERT INTO test4 (a4) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0); mysql>  INSERT INTO test1 VALUES  (1), (3), (1), (7), (1), (8), (4), (4); Query OK, 8 rows affected (0.01 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql>  SELECT * FROM test1; +------+ | a1 | 4735 As a result, the four tables contain the following data: Suppose that you insert the following values into table  test1  as shown here: •For transactional tables, failure of a statement should cause rollback of all changes performed by the statement. Failure of a trigger causes the statement to fail, so trigger failure also causes rollback. For nontransactional tables, such rollback cannot be done, so although the statement fails, any changes performed prior to the point of the error remain in effect. •An error during either a  BEFORE  or  AFTER  trigger results in failure of the entire statement that caused trigger invocation. •An  AFTER  trigger is executed only if any  BEFORE  triggers and the row operation execute successfully. •A  BEFORE  trigger is activated by the  attempt  to insert or modify the row, regardless of whether the attempt subsequently succeeds. •If a  BEFORE  trigger fails, the operation on the corresponding row is not performed.