sql server - Repeatable Read - am I understanding this right? -


trying understand sql server isolation levels - notably repeatable read.

i have sproc starts transaction , puts cursor around data (boo hiss). can fair chunk of data, can take while do.

it commit or rollback.

during time, before transaction has been closed, if calls method causes of affected rows read, understanding method stall until first method complete. served data (as long time-out doesn't occur first)

i think i'm right, question - i?!

repeatable read prevents selects lifting shared locks placed until end of transaction.

with transaction 1 read committed, can update row in transaction 2 after selected in transaction 1.

with transaction 1 repeatable read, cannot update row in transaction 2 after selected in transaction 1.

the scenarios:

read committed

1 select -- places shared lock , lifts it. 2 update -- places exclusive lock. succeeds. 1 select -- tries place shared lock conflicts exclusive lock placed 2. locks. 

repeatable read

1 select -- places shared lock , keeps 2 update -- tries places exclusive lock it's not compatible shared lock. locks 1 select -- lock placed. succeeds. 

update:

as question: in sql server, selects not lock each other repeatable read, since shared locks place compatible each other:

create table t_lock (id int not null primary key, value int not null) insert    t_lock values (1, 1)  -- session 1  set transaction isolation level repeatable read begin transaction declare @id int declare cr_lock cursor dynamic select  id    t_lock open    cr_lock fetch   cr_lock  id -- 1  -- session 2  set transaction isolation level repeatable read begin transaction declare @id int declare cr_lock cursor dynamic select  id    t_lock open    cr_lock fetch   cr_lock  id -- 1  -- session 1  deallocate cr_lock commit  -- session 2  deallocate cr_lock commit 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -