` Printed Icetips Article

Icetips Article



Par2: MS SQL record locking
2013-01-07 -- Duppie
 
n MS SQL you need to do something like this.

Wrapping your SELECT in a transaction while using WITH (XLOCK,READPAST) 
locking hint will get the results you want. Just make sure those other 
concurrent reads are NOT using WITH (NOLOCK). READPAST allows other 
sessions to perform the same SELECT but on other rows.

BEGIN TRAN
   SELECT *
   FROM  WITH (XLOCK,READPAST)
   WHERE RowId = @SomeId

   -- Do SOMETHING

   UPDATE 
   SET =@somevalue
   WHERE RowId=@SomeId
COMMIT



Printed May 8, 2024, 4:52 am
This article has been viewed/printed 35127 times.