1

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.

user3865748
  • 21
  • 2
  • 5

1 Answers1

4

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”.

tombom
  • 3,208
  • 1
  • 22
  • 28