Skip to Content
MySQL 8 Cookbook
book

MySQL 8 Cookbook

by Karthik Appigatla
January 2018
Intermediate to advanced
446 pages
12h 57m
English
Packt Publishing
Content preview from MySQL 8 Cookbook

How to do it...

To start a transaction (set of SQLs), execute the START TRANSACTION or BEGIN statement:

mysql> START TRANSACTION;or mysql> BEGIN;

Then execute all the statements that you wish to be inside a transaction, such as transferring 100 from A to B:

mysql> SELECT balance INTO @a.bal FROM account WHERE account_number='A';Programmatically check if @a.bal is greater than or equal to 100 mysql> UPDATE account SET balance=@a.bal-100 WHERE account_number='A';mysql> SELECT balance INTO @b.bal FROM account WHERE account_number='B';Programmatically check if @b.bal IS NOT NULL mysql> UPDATE account SET balance=@b.bal+100 WHERE account_number='B';

After making sure that all the SQLs are executed successfully, execute the COMMIT statement, which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Cookbook

MySQL Cookbook

Paul DuBois
Advanced MySQL 8

Advanced MySQL 8

Eric Vanier, Birju Shah, Tejaswi Malepati

Publisher Resources

ISBN: 9781788395809Other