Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 About the rowlock xlock

Author  Topic 

Ben Au
Starting Member

1 Post

Posted - 2008-07-27 : 05:24:23
Hi everybody,

--Session1
--Create the sample table and data
use Test
go
if object_id('XLockShareCluster') is not null
drop table XLockShareCluster
go
;with
L0 as (select 1 as ID union all select 1),
L1 as (select a.ID from L0 as a ,L0 as b),
L2 as (select a.ID from L1 as a ,L1 as b),
L3 as (select a.ID from L2 as a ,L2 as b),
L4 as (select a.ID from L3 as a ,L3 as b),
L5 as (select a.ID from L4 as a ,L4 as b),
SeqID as (select row_number()over(order by ID ) as ID from L5)


select ID,'A' as Name,3 as data into XLockShareCluster from SeqID where ID<=5000

alter table XLockShareCluster
alter column ID int not null

alter table XLockShareCluster
add constraint PK_XLockShareCluster
primary key clustered
(ID)on [primary]

create index IX_Name on XLockShareCluster(Name)

update XLockShareCluster
set name='B'
where ID=1

update XLockShareCluster
set name='C'
where ID=2

go

update statistics XLockShareCluster


--Session 2
--Put a rowlock xlock on record ID = 1.
use Test
go
select * from XLockShareCluster where ID=1


An XLock hold on the record ID=1 in session 2, Why can I select the record where ID=1 ?

--Session 4
use Test
go
select * from XLockShareCluster with(holdlock) where ID=1


It will wait until the Session2 commit tran.


Who can tell me the truth ?

-----------------------------------------------------------------
thanks for your help.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-07-27 : 15:24:11
>> An XLock hold on the record ID=1 in session 2, Why can I select the record where ID=1 ?

How did you put lock? Didn't see any code.
Go to Top of Page
   

- Advertisement -