Start transaction,COMMIT
, AndROLLBACK
Syntax
From: http://dev.mysql.com/doc/refman/5.0/en/commit.html
Of course, the article noted from MySQL, but MySQL, SQL Server, Oracle start tracmsaction, commit, and rollback syntax are no problem in DML.
I hope this article cocould help you understand how to using "Start transaction,COMMIT
, AndROLLBACK
Syntax ".
START TRANSACTION [WITH CONSISTENT SNAPSHOT] | BEGIN [WORK]COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]SET autocommit = {0 | 1}
The commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
Or commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">BEGIN
Statement begins a new transaction. Commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">COMMIT
Commits the current transaction, making its changes permanent. Commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
Rolls back the current transaction, canceling its changes. The commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">SET autocommit
Statement disables or enables the default autocommit mode for the current session.
Beginning with MySQL 5.0.3, the optionalWORK
Keyword is supported for commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">COMMIT
And commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
, As areCHAIN
AndRELEASE
Clses.CHAIN
AndRELEASE
Can be used for additional control over Transaction completion. The value ofcompletion_type
System variable determines the default completion behavior. SeeSection 5.1.3, "server system variables".
TheAND CHAIN
Clause causes a new transaction to begin as soon as the current one ends, and the new transaction has the same isolation level as the just-terminated transaction.RELEASE
Clause causes the server to disconnect the current client session after terminating the current transaction. IncludingNO
Keyword suppressesCHAIN
OrRELEASE
Completion, which can be useful ifcompletion_type
System variable is set to cause chaining or release completion by default.
By default, MySQL runs with autocommit mode enabled. this means that as soon as you execute a statement that updates (modifies) a table, MySQL stores the update on disk to make it permanent. to disable autocommit mode, use the following statement:
SET autocommit=0;
After disabling autocommit mode by settingautocommit
Variable to zero, changes to transaction-safe tables (such as thoseInnoDB
,BDB
, OrNDBCLUSTER
) Are not made permanent immediately. You must use commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">COMMIT
To store your changes to disk or commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
To ignore the changes.
To disable autocommit mode for a single series of statements, use the commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
Statement:
START TRANSACTION;SELECT @A:=SUM(salary) FROM table1 WHERE type=1;UPDATE table2 SET summary=@A WHERE type=1;COMMIT;
With commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
, Autocommit remains disabled until you end the transaction with commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">COMMIT
Or commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
. The autocommit mode then reverts to its previous state.
Commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">BEGIN
And commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">BEGIN WORK
Are supported as aliases of commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
For initiating a transaction. Commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
Is standard SQL syntax and is the recommended way to start an ad-hoc transaction.
Important
Extends APIs used for writing MYSQL client applications (such as JDBC) provide their own methods for starting transactions that can (and sometimes shocould) be used instead of sending a commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
Statement from the client. SeeChapter 20,Connectors and APIs, Or the documentation for your API, for more information.
The commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">BEGIN
Statement differs from the use ofBEGIN
Keyword that startsBEGIN ... END
Compound statement. The latter does not begin a transaction. SeeSection 12.8.1,"BEGIN ... END
Compound statement syntax".
You can also begin a transaction like this:
START TRANSACTION WITH CONSISTENT SNAPSHOT;
TheWITH CONSISTENT SNAPSHOT
Clause starts a consistent read for storage engines that are capable of it. This applies onlyInnoDB
. The effect is the same as issuing a commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">START TRANSACTION
Followed bySELECT
From anyInnoDB
Table. SeeSection 13.2.9.2, "consistent non-locking reads".WITH CONSISTENT SNAPSHOT
Clause does not change the current transaction isolation level, so it provides a consistent snapshot only if the current isolation level is one that allows consistent read (REPEATABLE READ
OrSERIALIZABLE
).
Beginning a transaction causes any pending transaction to be committed. SeeSection 12.4.3, "statements that cause an implicit commit", For more information.
Beginning a transaction also causes table locks acquired with unlock
Tables Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html ">LOCK TABLES
To be released, as though you had executed unlock
Tables Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html ">UNLOCK TABLES
. Beginning a transaction does not release a global read lock acquiredFLUSH TABLES WITH READ LOCK
.
For best results, transactions shocould be stored med using only tables managed by a single transaction-safe storage engine. Otherwise, the following problems can occur:
If you use tables from more than one transaction-safe storage engine (suchInnoDB
AndBDB
), And the transaction isolation level is notSERIALIZABLE
, It is possible that when one transaction commits, another ongoing transaction that uses the same tables will see only some of the changes made by the first transaction. that is, the atomicity of transactions is not guaranteed with mixed engines and inconsistencies can result. (If mixed-engine transactions are infrequent, you can useSET TRANSACTION ISOLATION LEVEL
To set the isolation levelSERIALIZABLE
On a per-transaction basis as necessary .)
If you use tables that are not transaction-safe within a transaction, changes to those tables are stored at once, regardless of the status of autocommit mode.
If you issue a commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
Statement after updating a non-transactional table within a transaction,ER_WARNING_NOT_COMPLETE_ROLLBACK
Warning occurs. Changes to transaction-safe tables are rolled back, but not changes to non-transaction-safe tables.
Each transaction is stored in the binary log in one chunk, upon commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">COMMIT
. Transactions that are rolled back are not logged .(Exception: Modifications to non-transactional tables cannot be rolled back. If a transaction that is rolled back between des modifications to non-transactional tables, the entire transaction is logged with a commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
Statement at the end to ensure that modifications to the non-transactional tables are replicated.) SeeSection 5.2.3, "the binary log".
You can change the isolation level for transactionsSET TRANSACTION ISOLATION LEVEL
. SeeSection 12.4.6,"SET TRANSACTION
Syntax".
Rolling back can be a slow operation that may occur implicitly without the user having explicitly asked for it (for example, when an error occurs). Because of this,SHOW PROCESSLIST
DisplaysRolling back
InState
Column for the session, not only for explicit rollbacks completed MED with the commit, and
Rollback Syntax "href =" http://dev.mysql.com/doc/refman/5.0/en/commit.html ">ROLLBACK
Statement but also for implicit rollbacks.