Book Image

Mastering MariaDB

By : Federico Razzoli
Book Image

Mastering MariaDB

By: Federico Razzoli

Overview of this book

Table of Contents (19 chapters)
Mastering MariaDB
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Transactions


The user can use a set of SQL statements to control transactions. These statements allow us to explicitly start, commit, or rollback a transaction, but in some cases such operations are implicit. We can also set an isolation level, which determines which locks are acquired and how consistent the reads are. We can also declare in advance that a transaction is read only; this allows InnoDB to execute more internal optimizations.

The transactions life cycle

Usually, MariaDB transactions start with the START TRANSACTION statement and end with COMMIT or ROLLBACK. BEGIN WORK is a synonym for START TRANSACTION, but it does not work within stored programs, because the BEGIN and END keywords are used to enclose code blocks. The general syntax is:

START TRANSACTION;
<one or more statements>
COMMIT;

The START TRANSACTION AND CHAIN command means that another transaction will immediately start after COMMIT or ROLLBACK, so it is useless to repeat START TRANSACTION.

Some statements are not...