BEGIN SELECT num FROM table_name where log_id ='1' -- num | 0 -- 等待 事务B 执行 UPDATE table_name set num = num +1where log_id ='1' -- 事务B 提交后, 更新成功结果 由 0 跳到 2 COMMIT;
B事物 (后开启)
1 2 3 4 5 6
BEGIN SELECT num FROM table_name where log_id ='1' -- num | 0 UPDATE table_name set num = num +1where log_id ='1' -- num | 1 COMMIT;
不能成功
1 2 3 4 5
BEGIN SELECT num FROM table_name where log_id ='1' UPDATE table_name set num = num +1where log_id ='1'and num =0 COMMIT; -- affect row 0