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 ...

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.