They run in separate transactions if autocommit=1
. Suppose you define
CREATE TABLE test ( id int PRIMARY KEY )//
CREATE PROCEDURE sp_test_trans()
BEGIN
INSERT INTO test (id) VALUES (1);
INSERT INTO test (id) VALUES (2);
ROLLBACK;
END//
If you run this procedure with autocommit=0
, the ROLLBACK
will undo the insertions. If you run it with autocommit=1
, the ROLLBACK
will do nothing. Fiddle here.
Another example:
CREATE PROCEDURE sp_test_trans_2()
BEGIN
INSERT INTO test (id) VALUES (1);
INSERT INTO test (id) VALUES (1);
END//
If you run this procedure with autocommit=0
, failure of the second insert will cause a ROLLBACK
undoing the first insertion. If you run it with autocommit=1
, the second insert will fail but the effects of the first insert will not be undone.