Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:25:11+00:00 2026-06-12T23:25:11+00:00

Can someone tell me if it is possible to call another procedure from within

  • 0

Can someone tell me if it is possible to call another procedure from within a procedure and if any part of either procedure fails, roll everything back?

If this is possible, can someone please show me a tiny example of how this would be implemented?

EDIT: Procedure “b” fails but procedure “a” still inserts a row into table “a”. It’s my understanding that if any part of the insert fails that everything (both inserts) is rolled back which is not happening here. The questions is why not?

Procedure “a”

BEGIN
  DECLARE b INT DEFAULT 0;
  DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK;
  DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;

  START TRANSACTION;
    INSERT INTO a(a)
    VALUES(iA);

     CALL b(iB,LAST_INSERT_ID(),@b);
     SELECT @b INTO b;

     IF b !=1 THEN
        ROLLBACK;
      ELSE
        COMMIT;
  END IF;
END

Procedure “b”

BEGIN
  DECLARE b INT DEFAULT 0;
  DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK;
  DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;

  START TRANSACTION;
    INSERT INTO b VALUES(iB,id);
    SET b=1;
  COMMIT;
END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:25:12+00:00Added an answer on June 12, 2026 at 11:25 pm

    You will need to handle transactions in both procedures, but the proc that is calling the other, should check for the return value and rollback it’s transactions based on that. Here is an example of the inner proc:

    How to detect a rollback in MySQL stored procedure?

    you would then check for p_return_code and do a rollback of the parent transaction.

    EDIT:

    What I think is happening is that inner SP COMMIT or ROLLBACK affect outer SP TRANSACTION. This code works for me, if inner SP fail it rolls back both insert statements. First call to ab() works, new user record gets inserted and new game record gets inserted, if we remove record from the games table and run ab() again, because user id already exists it rolls back games table insert:

    create procedure ab()
    BEGIN
      START TRANSACTION;
        INSERT INTO games (title) VALUES ('bad game');
        CALL ba(@ret);
        IF @ret!=0 THEN
          ROLLBACK;
        ELSE
          COMMIT;
        END IF;
    END;
    
    
    create procedure ba(OUT return_value tinyint unsigned)
    BEGIN
      DECLARE exit handler for sqlexception
      BEGIN
        set return_value = 1;
      END;
    
      INSERT INTO users (id) VALUES(1);
      set return_value = 0;
    END;
    

    To test use call ab();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me is it possible to somehow call c function or simply
Can someone tell me, if it is possible to write a batch to c#
Can someone tell me if what I want to do is possible (asp.net 4)
Can someone tell me if it is possible to highlight certain words (provided by
Can someone tell me if it is possible to add a border to a
i´m using GZipStream to gzip string. Can someone tell me if it is possible
Can someone tell me if it's possible to create an apk file during runtime?
Can someone tell me if in db2 db is possible to export a table
Possible Duplicate: Property vs. instance variable Can someone tell me what is the difference
Possible Duplicate: Why and When to use node js? Can someone tell me why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.