Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Enrollment relation has one record per student-class pair such that the student is enrolled in the
class. For each of the following transactions, state the SQL isolation level you would use and explain
why you chose it and why you wouldn't use other isolation levels by citing examples of anomalies
(related to Read-Write, Write-Read, Write-Write).
Answer:
Transaction1: Read Uncommitted
We are inserting a new enrolment, so we need not worry about any existing row to be
effected by this insert operation.
Transaction2: Read Committed
As in this transaction, we are updating the enrolment (effecting the existing row) , so we must
ensure no other transaction should read this row before commit takes place. Or we need
exclusive lock on this row.
Transaction3: SERIALIZABLE.
As in this transaction we need to perform two steps
Step#1: Select the class with least number of students.
Step#2: Insert a new faculty member for this class in “Faculty”
Now for step1, we must ensure that there should be no other transaction updating or inserting
the Ennoblement, while we are reading for the class with the least number of students i.e.
Phantom read Problem.
Transaction4: SERIALIZABLE.
Again the same case, while we are selecting the data we don’t want any other transaction to
update and insert.
Give a populated database instance and SQL statements for T1 and T2 such that result of running T2
with the given SQL isolation level is different from running T3. For each situation, also explain why
the results are different.
Answer:
create table student ( regnum integer,
name varchar(100),
address varchar(200))
Both Transactions will execute in serial fashion. And results of both select
statements will be same
In transactions 3: The first query result will be 5 and next same query result will
be 6. (phantom reads problem)
Case 2:
Transaction 2 (REPEATABLE READ) Transaction 1 (SERIALIZABLE)
/* Query 1 */
SELECT * FROM student
WHERE regno = 5;
/* Query 2 */
/* Query 2 */
UPDATE student set address = ‘xyz’
WHERE regno = 5;
/* Query 1 */ COMMIT;
SELECT * FROM student
WHERE regno = 5;
In the above transaction both statements in transaction 2 will show same result
In the above transaction select first select query will show previous address and
second query will show new address xyz. SERIALIZABLE and REPEATABLE READ
isolation level, the DBMS must return the old value. At READ COMMITTED and
READ UNCOMMITTED, the DBMS may return the updated value.
Case 3:
/* Query 1 */
SELECT * FROM student
WHERE regno = 5;
Rollback
In the above transaction both statements in transaction 2 will show same result
as no commit has been done and roll back will not cause any problem
Transaction 3 (READ UNCOMMITTED) Transaction 1 (SERIALIZABLE)
/* Query 1 */
SELECT * FROM student
WHERE regno = 5;
/* Query 2 */
UPDATE student set address = ‘xyz’
WHERE regno = 5;
/* No commit here */
/* Query 1 */
SELECT * FROM student
WHERE regno = 5;
Query in transaction 3 will show dirty read problem when the rollback will occur
in transaction 1.