SQL Transactions Exercises Consider table Item(name,price) where name is a key,
ID: 3841996 • Letter: S
Question
SQL Transactions Exercises
Consider table Item(name,price) where name is a key, and the following two concurrent transactions.
T1:
Begin Transaction;
Update Item Set price = 2*price Where name = 'pencil';
Insert Into Item Values ('scissors’, $100);
Commit;
T2:
Begin Transaction;
select max(Price) as a1 From Item;
select max(Price) as a2 from Item;
Commit;
Assume that the individual statements in each transaction always execute atomically. Suppose initially there are two tuples in Item: (pencil,1000) and (pen,900). Each transaction runs once and commits. Transaction T1 always executes with isolation level Serializable.
(a) If transaction T2 executes with isolation level Serializable, what possible pairs of values a1 and a2 are returned by T2?
(b) If transaction T2 executes with isolation level Repeatable-Read, what possible pairs of values a1 and a2 are returned by T2?
(c) If transaction T2 executes with isolation level Read-Committed, what possible pairs of values a1 and a2 are returned by T2?
(d) If transaction T2 executes with isolation level Read-Uncommitted, what possible pairs of values a1 and a2 are returned by T2?
Explanation / Answer
Its given Transaction T1 always executes with isolation level Serializable.
therefore T1 happens at once, with commit.
1. since T2 is also serializible, it is allowed to read only committed data by T1, so we will get 2000,2000
2.if t2 is repeatable read, update in T1 is not allowed to update unless we rollback t2,so we will get 1000,1000 or 2000,2000
3.if t2 is read committed,reads are only allowed after the transactions are completed, so based on t1 commit we might get 1000,1000 or 2000,2000
4.if t2 is read uncommitted, we are allowed dirty reads that means we can read before t1 commits which might give,
1000,1000 1000,2000 2000,2000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.