Базы данных
Транзакции
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;
start transaction
commit
rollback
start 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 ≥ Δ begin t_1 = t_1 − Δ end if
if t_1 + t_2 ≥ Δ begin t_2 = t_2 − Δ end if
Аномалия / Уровень | S | SN | RR | RC | RU |
---|---|---|---|---|---|
Косая запись | − | + | + | + | + |
Фантомная запись | − | − | + | + | + |
Неповторяемое чтение | − | − | − | + | + |
грязное чтение | − | − | − | − | + |
start transaction [режим] [изоляция] [настройки]
read {only | write}
[isolation level уровень]
commit [work] [and [no] chain]
rollback [work] [and [no] chain]
start transaction isolation level serializable; // 1 start transaction isolation level read committed; // 2
start transaction isolation level read committed; // 1 start transaction isolation level serializable; // 2 commit and no chain; // 3 rollback;
savepoint имя
rollback to savepoint имя
release savepoint имя
add constraint ... режим
set constraints {all|ограничения} {deferred|immediate}