1
0
Files
sql-study/MySQL/transaction-error/user_a.sql
2025-11-04 21:35:51 +08:00

42 lines
938 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- example 1
-- ========== 0 =========
start transaction;
-- A先查询
select *
from customer;
-- ========== 1 =========
-- ========== 2 =========
-- 在 B 添加数据后A 尝试进行修改。奇怪的是,明明查询不到,居然可以修改成功
update customer
set username = 'wuhu'
where id = 1;
-- A 再次查询表中数据,发现修改的那一行现身了
select *
from customer;
commit;
-- ========== 3 =========
-- example 2
-- ========== 0 =========
start transaction;
-- A先查询查到数据如下
-- 1,Fortern
-- 2,Maxin
-- 3,MooGeo
select *
from customer;
-- ========== 1 =========
-- ========== 2 =========
-- A 备份表中数据到另一个表
insert into customer_back select * from customer;
commit;
-- 结果备份表中的数据居然是被其他事物修改的数据!!
select * from customer_back;
-- 为什么会这样?
-- ========== 3 =========
select * from customer where id = 1;