Hi everybody,--Session1--Create the sample table and datause Testgoif object_id('XLockShareCluster') is not nulldrop table XLockShareClustergo;withL0 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<=5000alter table XLockShareCluster alter column ID int not nullalter table XLockShareClusteradd constraint PK_XLockShareClusterprimary key clustered(ID)on [primary]create index IX_Name on XLockShareCluster(Name)update XLockShareCluster set name='B' where ID=1update XLockShareCluster set name='C' where ID=2goupdate statistics XLockShareCluster--Session 2--Put a rowlock xlock on record ID = 1.use Testgoselect * 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 4use Testgoselect * 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.