0

I'm using RDS Aurora (MySQL 5.6)

By default Auto Commit flag is enabled. I have a transaction as follows

BEGIN;
INSERT INTO .....;// STATEMENT 1
INSERT INTO ......;//STATEMENT 2
COMMIT;

I'm expecting both the Inserts to be commited only when COMMIT is executed. But Statement 1 is Commiting as soon as it got executed.

So I wanted to know What does BEGIN do here ??

I was assuming that BEGIN does the task of disabling Auto Commit , Can someone also explain the difference between BEGIN and START TRANSACTION as well.

  • BEGIN starts code block. It is not relative to transactions. The only purpose of a BEGIN-END block (in addition to code structuring) is to create an existence/visibility area for the structures defined in it (variables, handlers, etc.). – Akina Mar 4 at 13:12
1

The manual has this to say:

BEGIN and BEGIN WORK are supported as aliases of START TRANSACTION for initiating a transaction. START TRANSACTION is standard SQL syntax, is the recommended way to start an ad-hoc transaction, and permits modifiers that BEGIN does not.

The BEGIN statement differs from the use of the BEGIN keyword that starts a BEGIN ... END compound statement. The latter does not begin a transaction. See Section 13.6.1, “BEGIN ... END Compound Statement”.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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