insert into accs (id, money) values (1, 0);
update accs set money = money - 100 where id = 1; update accs set money = money + 100 where id = 2;
begin transaction
commit
rollback
begin transaction; if ((select money from accs where id = 1) ≤ 100) rollback; update accs set money = money - 100 where id = 1; update accs set money = money + 100 where id = 2; commit;
Транзакция 1 | Транзакция 2 |
---|---|
retrieve t update t commit | retrieve t update t commit |
Транзакция 1 | Транзакция 2 |
---|---|
update t commit | update t rollback |
Транзакция 1 | Транзакция 2 |
---|---|
retrieve t commit | update t rollback |
Транзакция 1 | Транзакция 2 |
---|---|
retrieve t_1 retrieve t_2 commit | update t_1 = t_1 - 10 update t_2 = t_2 + 10 commit |
– | S | X | |
– | + | + | + |
S | + | + | − |
X | + | − | − |
Транзакция 1 | Транзакция 2 |
---|---|
retrieve t_1 update t_2 – | retrieve t_2 update t_1 |
Транзакция 1 | Транзакция 2 |
---|---|
retrieve t commit | update t rollback |
if (t_1 + t_2 - Δ ≤ 0) begin t_1 = t_1 - Δ end
if (t_1 + t_2 - Δ ≤ 0) begin t_2 = t_2 - Δ end
Аномалия / Уровень | S | SN | RR | RC | RU |
---|---|---|---|---|---|
Косая запись | − | + | + | + | + |
Фантомная запись | − | − | + | + | + |
Неповторяемое чтение | − | − | − | + | + |
грязное чтение | − | − | − | − | + |
start transaction [read {only | , write}] [isolation level уровень] [настройки]
commit [work] [and [no] chain]
rollback [work] [and [no] chain]
savepoint имя
rollback to имя
release имя