TiDBTiDB Docs Dash 2024

Jan 9 - Jan 12 (UTC)
Join us to improve docs and win a prize!
Sign InTry Free

BEGIN

This statement starts a new transaction inside of TiDB. It is similar to the statements START TRANSACTION and SET autocommit=0.

In the absence of a BEGIN statement, every statement will by default autocommit in its own transaction. This behavior ensures MySQL compatibility.

Synopsis

BeginTransactionStmt
BEGINPESSIMISTICOPTIMISTICSTARTTRANSACTIONREADWRITEONLYWITHTIMESTAMPBOUNDTimestampBoundWITHCONSISTENTSNAPSHOT

Examples

mysql> CREATE TABLE t1 (a int NOT NULL PRIMARY KEY); Query OK, 0 rows affected (0.12 sec) mysql> BEGIN; 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)

MySQL compatibility

TiDB supports the syntax extension of BEGIN PESSIMISTIC or BEGIN OPTIMISTIC. This enables you to override the default transactional model for your transaction.

See also

Was this page helpful?

Download PDFRequest docs changesAsk questions on Discord
Playground
New
One-stop & interactive experience of TiDB's capabilities WITHOUT registration.
Products
TiDB
TiDB Dedicated
TiDB Serverless
Pricing
Get Demo
Get Started
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.