MySQL AUTOCOMMIT status while using BEGIN and START TRANSACTION -
i need use transaction in project on mysql. i'm not sure if have use mysql_query("set autocommit=0");
or not.
know have 2 options:
- begin
- start transaction
also have heard 1 of both items not need using autocommit = 0
.
please me know when have use autocommit = 0
actually, begin
or start transaction
?
thank you.
as explained in the manual:
by default, mysql runs autocommit mode enabled. means execute statement updates (modifies) table, mysql stores update on disk make permanent. change cannot rolled back.
to disable autocommit mode implicitly single series of statements, use
start transaction
statement:start transaction; select @a:=sum(salary) table1 type=1; update table2 set summary=@a type=1; commit;
with
start transaction
, autocommit remains disabled until end transactioncommit
orrollback
. autocommit mode reverts previous state.
the manual goes on say:
to disable autocommit mode explicitly, use following statement:
set autocommit=0;
after disabling autocommit mode setting
autocommit
variable zero, changes transaction-safe tables (suchinnodb
orndbcluster
) not made permanent immediately. must usecommit
store changes disk orrollback
ignore changes.
autocommit
session variable , must set each session. disable autocommit mode each new connection, see description ofautocommit
system variable @ section 5.1.3, âserver system variablesâ.
begin
,begin work
supported aliases ofstart transaction
initiating transaction.start transaction
standard sql syntax , recommended way start ad-hoc transaction.
Comments
Post a Comment