Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select ..FOR UPDATE is to Oracle as _____ is to SQLServe
Message
De
16/02/1999 08:20:56
 
 
À
16/02/1999 05:23:51
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00187943
Message ID:
00187978
Vues:
27
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform