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

Read uncommitted

The current transaction can read data written by another uncommitted transaction, which is also called dirty read.

For example, A wants to add some amount to his account and transfer it to B. Assume both the transactions happen at the same time; the flow will be like this.

A initially has $400 and wants to transfer $500 to B after adding $500 to his account.

# Transaction 1 (adding amount) # Transaction 2 (transferring amount)
BEGIN;
BEGIN;
UPDATE account SET balance=balance+500 WHERE account_number='A';
--
 --
SELECT balance INTO @a.bal FROM account WHERE account_number='A'; # A sees 900 here
ROLLBACK; # Assume due to some reason the transaction got rolled back

--

--
# A transfers 900 to B since A has ...

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