Transaction
2019-08-26 10:28:14 0 举报
SQL
作者其他创作
大纲/内容
UPDATE account SET balance = 1700 WHERE account_id = 1;
SELECT * FROM account;+----+------------+---------+| id | account_id | balance |+----+------------+---------+| 1 | 1 | 1700 || 4 | 2 | 1800 |+----+------------+---------+
Time Line
Transaction A\"Transfer 500 from 1 to 2\"
locked
blocking
SELECT * FROM account;+----+------------+---------+| id | account_id | balance |+----+------------+---------+| 1 | 1 | 1000 || 4 | 2 | 2000 |+----+------------+---------+
lock account_id 1
Transaction B\"Transfer 200 from 2 to 1\"
UPDATE account SET balance = 2500 WHERE account_id = 2;
START TRANSACTION;
UPDATE account SET balance = 1000 WHERE account_id = 1;
SELECT * FROM account;+----+------------+---------+| id | account_id | balance |+----+------------+---------+| 1 | 1 | 1000 || 4 | 2 | 2500 |+----+------------+---------+
SELECT * FROM account;+----+------------+---------+| id | account_id | balance |+----+------------+---------+| 1 | 1 | 1500 || 4 | 2 | 2000 |+----+------------+---------+
COMMIT;
unlock all
UPDATE account SET balance = 1800 WHERE account_id = 2;
SELECT * FROM account;+----+------------+---------+| id | account_id | balance |+----+------------+---------+| 1 | 1 | 1700 || 4 | 2 | 1800 |+----+------------+---------+
0 条评论
下一页