Transaction Management SQL Isolation Level: 1. Read Committed
Transaction Management SQL Isolation Level: 1. Read Committed
1. READ COMMITTED
In select query it will take only commited values of table. If any transaction is
opened and incompleted on table in others sessions then select query will wait till
no transactions are pending on same table.
2. READ UNCOMMITTED
If any table is updated(insert or update or delete) under a transaction and same
transaction is not completed that is not committed or roll backed then uncommitted
values will displaly(Dirty Read) in select query of "Read Uncommitted" isolation
transaction sessions. There won't be any delay in select query execution because
this transaction level does not wait for committed values on table.
3. REPEATABLE READ
select query data of table that is used under transaction of isolation level
"Repeatable Read" can not be modified from any other sessions till transcation is
completed.
4. SERIALIZABLE
Serializable Isolation is similar to Repeatable Read Isolation but the difference is it
prevents Phantom Read. This works based on range lock. If table has index then it
locks records based on index range used in WHERE clause(like where ID between 1
and 3). If table doesn't have index then it locks complete table.
5. SNAPSHOT
Snapshot isolation is similar to Serializable isolation. The difference is Snapshot does
not hold lock on table during the transaction so table can be modified in other
sessions. Snapshot isolation maintains versioning in Tempdb for old data in case of
any data modification occurs in other sessions then existing transaction displays the
old data from Tempdb.
Scenario
Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(name: string, meets at: time, room: string, fid: integer)
Enrolled(snum: integer, cname: string)
Faculty(fid: integer, fname: string, deptid: integer)
The meaning of these relations is straightforward. For example, Enrolled 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.
1. Enroll a student identified by her snum into the class named ’Introduction to Database
Systems’.
2. Change enrollment for a student identified by her snum from one class to another class.
Solution
1. Because we are inserting a new row in the table Enrolled, we do not need any lock on the
existing rows. So we would use READ UNCOMMITTED.
2. Because we are updating one existing row in the table Enrolled, we need an exclusive lock
on the row which we are updating. So we would use READ COMMITTED.
Reference: http://www.besttechtools.com/articles/article/sql-server-isolation-levels-by-example
Scenario
Initially : A = 0
T1-T2-T3: A = 1
T1-T3-T2: A= 2
T2-T1-T3:A=1
T2-T3-T1:A=2
T3-T1-T2:A = ?
T3-T2-T1: A=3