Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select ..FOR UPDATE is to Oracle as _____ is to SQLServe
Message
From
16/02/1999 08:20:56
 
 
To
16/02/1999 05:23:51
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00187943
Message ID:
00187978
Views:
26
>How do I lock 1 row in a table from an ODBC Connection.
>eg. On Oracle I issue:
>select * from T where (primary_key) = (some_value) FOR UPDATE;
>
>
>COnversly how do I test if this 1 row is locked?
>eg.On Oracle I:
>select * from T where (primary_key) = (some_value) FOR UPDATE NOWAIT;
>
>Is there a similar mechanism on sql server???

For SQL Server 7.0:

BEGIN TRANSACTION
SELECT * FROM table (ROWLOCK HOLDLOCK) WHERE pkey = value
...
COMMIT TRANSACTION

The locking hint HOLDLOCK will cause SQL Server 7.0 to hold the lock for the duration of the transaction.

For 6.5 you can do basically the same thing but you'll have to lock the entire page, which could cause concurrency problems. Change the locking hints to (PAGLOCK HOLDLOCK).

IMPORTANT: For both of these options, SQL Server may acquire multiple locks while searching for the correct row. ALL the locks will be held until the end of the transaction.

Maybe there's another way to do whatever you're trying to do?

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform