Is it intended behavior that if I call a stored procedure inside a stored procedure will automatically commit?


pseudo procedure proc1

create procedure proc1(in var1 int, out var2 int)
  start transaction;
  -- some code here

pseudo procedure proc2, the one will call the proc1

create procedure proc2()
  start transaction;
    -- modify some data here
    call proc1(0, var2);

    if var != 0 then
      leave lbl_begin;

Even the rollback on proc2 is executed, the data modified before the call of the proc1 is still committed.

Is it a bug or its an intended behavior?

  • 1
    Normal behavior. You need to learn to commit ALL your work...or none of it. See ACID Compliant for more info. Commented Feb 8, 2020 at 12:23
  • @MichaelKutz no my concern is when I tried to rollback the data is still committed.
    – zer09
    Commented Feb 9, 2020 at 4:59
  • 1
    Thsts because you called commit Commented Feb 9, 2020 at 11:18
  • I edited the question few hours ago, and set if var != 0 then rollback and exit the stored procedure that wont execute the commit.
    – zer09
    Commented Feb 9, 2020 at 13:03
  • Do you get the same thing if you avoid using stored procs?
    – Rick James
    Commented Feb 13, 2020 at 3:04

1 Answer 1


Beginning a transaction causes any pending transaction to be committed. See Section 13.3.3, “Statements That Cause an Implicit Commit”, for more information.

-- https://dev.mysql.com/doc/refman/8.0/en/commit.html


Transactions cannot be nested. This is a consequence of the implicit commit performed for any current transaction when you issue a START TRANSACTION statement or one of its synonyms.

-- https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html

That is, proc1's START closed proc2's START.

The first ROLLBACK closes the only open transaction, hence the second ROLLBACK has nothing to "roll back".

  • I started over and found documentation.
    – Rick James
    Commented Feb 13, 2020 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.