1. 程式人生 > >事務的隔離級別的演示:避免不可重復讀

事務的隔離級別的演示:避免不可重復讀

事務的隔離級別演示

1.1.1 演示避免不可重復讀
l 分別開啟兩個窗口A,B
l 設置A窗口的隔離級別:repeatable read;
SET SESSION TRANSACTION ISOLATION LEVEL repeatable read;
技術分享圖片
l 在A,B兩個窗口中開啟事務:
start transaction;
l 在B窗口完成轉賬
update account set money = money - 1000 where name= ‘小張‘;
update account set money = money + 1000 where name= ‘小鳳‘;
技術分享圖片
未提交事務!!!
l 在A窗口中進行查詢
select
from account;
**** 發現沒有轉賬成功:說明避免臟讀!!!
l 在B窗口中提交事務
commit;
l 在A窗口中再次查詢:
技術分享圖片
發現在一個事務中的多次查詢結果是一致!!!(已經避免不可重復讀)。

事務的隔離級別的演示:避免不可重復讀