IF Exists(Select 1 from sys.objects where name='foobar' and type='U')
Begin
Drop Table foobar
End
Create Table foobar (sno int,sname varchar(20))
Insert into foobar
Values(1,'Spurs'),(2,'Rockets'),(3,'Pelicans')
/*PRO:Repeatable Read does not allow Phantom Reads.*/
--Session 1
Set Transaction Isolation Level Repeatable Read
Begin Tran
Select * from Foobar
Waitfor Delay '00:00:05'
Select * from Foobar --No Phantom Reads
Commit
--Session 2
Set Transaction Isolation Level Repeatable Read
Begin Tran
Update foobar set sname='Bobcats' where sno=3
Commit
/*CON:Repeatable Read allows Phantom Inserts.*/
--Session 1
Set Transaction Isolation Level Repeatable Read
Begin Tran
Select * from Foobar
Waitfor Delay '00:00:05'
Select * from Foobar --Phantom Inserts
commit
--Session 2
Set Transaction Isolation Level Repeatable Read
Begin Tran
Insert into foobar Values(4,'Suns')
Commit