Transaction A | Transaction B |
BEGIN TRANSACTION; SELECT A FROM T; --sees the old state INSERT INTO T VALUES (7); SELECT A FROM T; --sees the old state + value 7 COMMIT; | BEGIN TRANSACTION; SELECT A FROM T; --sees the same old state SELECT A FROM T; --sees the old state without 7 SELECT A FROM T; --sees the old state without 7 COMMIT; --new transaction starts SELECT A FROM T; --sees the new state including 7 |
Transaction A | Transaction B |
--Empty Table T has a PRIMARY KEY on attribute PK BEGIN TRANSACTION; SELECT A FROM T; --sees an empty table INSERT INTO T VALUES(6); INSERT INTO T VALUES(7); SELECT A FROM T; --sees 6 and 7 SELECT A FROM T; --sees 6 and 7 COMMIT; --success | BEGIN TRANSACTION; SELECT A FROM T; --sees an empty table INSERT INTO T VALUES(5); INSERT INTO T VALUES(7); SELECT A FROM T; --sees 5 and 7 SELECT A FROM T; --sees 5 and 7 COMMIT; --fails due to a primary key violation on 7 |