0

I want to implement 'start transaction and rollback' on 2 queries that update a table in a stored procedure. I want the second query to only execute if the first query was successful. I really don't know how to do this. I can't seem to understand MySQL documentation. Here are my queries:

BEGIN
    UPDATE table SET status = 1 WHERE user_id = 1

    UPDATE table SET status = 2 WHERE user_id = 2 

END;
shekwo
  • 1,411
  • 1
  • 20
  • 50
  • I'm marking this duplicate, because I really think that doing this from a stored proc is how you would probably end up implementing your logic. – Tim Biegeleisen May 28 '18 at 12:50
  • One form of 'failure' is if an update does not find a row to update. This will not throw a system error or cause a handler to be invoked. You can check this by testing row_count(); immediately after the update statement. This has limited use since it supposes you know how many rows should be updated - but if only one then it may be useful. – P.Salmon May 28 '18 at 14:37

0 Answers0