Use this MySQL statement to start a transaction.


Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).



Use this statement to start a transaction. Transaction statements for a currently supported by the InnoDB, NDB Cluster, and BDB storage engines and are ignored if used with MyISAM tables. The WORK keyword is optional. Don't confuse the BEGIN statement with the BEGIN...END compound statement used in stored procedures and triggers. To eliminate confusion on this point, it's recommended you use the alias START TRANSACTION instead of BEGIN.

A transaction is permanently recorded when the session isses a COMMIT statement, starts another transaction, or terminates the connection. You can reverse a transaction by issuing a ROLLBACK statement if the transaction has not yet been committed. See the explanation in our MySQL documentation of the MySQL statements, COMMIT and ROLLBACK for more information on transactions. The MySQL statements, SAVEPOINT and the ROLLBACK TO SAVEPOINT may also be useful.


Here is an example of the how the MySQL statement BEGIN may be used in context:


INSERT DATA INFILE '/tmp/customer_orders.sql'
INTO TABLE orders;


In this example, if there was a problem after the batch of orders was inserted into the orders table, the MySQL statement, ROLLBACK could be issued instead of the MySQL statement, COMMIT shown here. ROLLBACK would remove the data imported by the INSERT DATA INFILE statement.