O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Suppose A wants to transfer to multiple accounts; even if a transfer to one account fails, the others should not be rolled back:

mysql> BEGIN;Query OK, 0 rows affected (0.00 sec)mysql> SELECT balance INTO @a.bal FROM account WHERE account_number='A';Query OK, 1 row affected (0.01 sec)mysql> UPDATE account SET balance=@a.bal-100 WHERE account_number='A';Query OK, 1 row affected (0.01 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> UPDATE account SET balance=balance+100 WHERE account_number='B';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> SAVEPOINT transfer_to_b;Query OK, 0 rows affected (0.00 sec)mysql> SELECT balance INTO @a.bal FROM account WHERE account_number='A';Query OK, 1 row affected ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required