title | summary | aliases | ||
---|---|---|---|---|
START TRANSACTION | TiDB SQL Statement Reference |
An overview of the usage of START TRANSACTION for the TiDB database. |
|
This statement starts a new transaction inside of TiDB. It is similar to the statement BEGIN
.
In the absence of a START TRANSACTION
statement, every statement will by default autocommit in its own transaction. This behavior ensures MySQL compatibility.
BeginTransactionStmt:
BeginTransactionStmt ::=
'BEGIN' ( 'PESSIMISTIC' | 'OPTIMISTIC' )?
| 'START' 'TRANSACTION' ( 'READ' ( 'WRITE' | 'ONLY' ( ( 'WITH' 'TIMESTAMP' 'BOUND' TimestampBound )? | AsOfClause ) ) | 'WITH' 'CONSISTENT' 'SNAPSHOT' | 'WITH' 'CAUSAL' 'CONSISTENCY' 'ONLY' )?
AsOfClause ::=
( 'AS' 'OF' 'TIMESTAMP' Expression)
mysql> CREATE TABLE t1 (a int NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (0.12 sec)
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO t1 VALUES (1);
Query OK, 1 row affected (0.00 sec)
mysql> COMMIT;
Query OK, 0 rows affected (0.01 sec)
-
START TRANSACTION
immediately starts a transaction inside TiDB. This differs from MySQL, whereSTART TRANSACTION
lazily creates a transaction. ButSTART TRANSACTION
in TiDB is equivalent to MySQL'sSTART TRANSACTION WITH CONSISTENT SNAPSHOT
. -
The statement
START TRANSACTION READ ONLY
is parsed for compatibility with MySQL, but still allows write operations.