advanced question - 'xlock' hint on record not locking select * from table
From: Francisco D. Kurpiel (francisco.kurpiel_at_westbest.com.br)
Date: 02/27/04
- Next message: keyur: "function for current date"
- Previous message: Scott Elgram: "Re: Stored procedure/trigger and scripts"
- Next in thread: Dejan Sarka: "Re: advanced question - 'xlock' hint on record not locking select * from table"
- Reply: Dejan Sarka: "Re: advanced question - 'xlock' hint on record not locking select * from table"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 27 Feb 2004 16:50:16 -0300
I have a problem with locking on sql server 2000 sp3. I select one record
from a table using the primary key on the where clause, inside a transaction
with serializable level. In another connection, I try to do a simple select
* from sametable (also using serializable transaction level) and this
command runs without locking, when it should wait for the exclusive lock
that is held by another connection to be released.
I wrote two scripts to simulate my problem. The first creates a table,
populate it, starts a connection and selects a record using the xlock hint
leaving the transaction and the locks open. Another query analyzer must be
opened (leaving this also open) to run the second script. This script do a
simple select * from tbl. This script returns all records, including the
records that is xlocked on the another connection.
SCRIPT 1
if exists (select 1 from sysobjects where name = 'bla')
drop table bla
go
create table bla (
id int not null,
nome nvarchar(256) not null,
constraint pk_bla primary key clustered (id),
constraint un_bla_nome unique (nome)
)
go
insert into bla values (1, 'Some thing')
insert into bla values (2, 'Some other thing')
go
set transaction isolation level serializable
begin transaction
select *
from bla (xlock, rowlock)
where id=1
execute sp_lock @@spid
--rollback transaction
SCRIPT 2 (must be run on another query analyzer window)
set transaction isolation level serializable
begin transaction
select *
from bla (holdlock, rowlock)
execute sp_lock @@spid
rollback transaction
- Next message: keyur: "function for current date"
- Previous message: Scott Elgram: "Re: Stored procedure/trigger and scripts"
- Next in thread: Dejan Sarka: "Re: advanced question - 'xlock' hint on record not locking select * from table"
- Reply: Dejan Sarka: "Re: advanced question - 'xlock' hint on record not locking select * from table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|