Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Row Locking
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
01263435
Message ID:
01265102
Vues:
14
>Hi Guys,
>I am converting a VFP app to SQL Server Database. This app has stock control and about 50 users use the system simultaneously. A lot of inventory management. I need to use pessimistic locking, So the stock on hand gets incremented or decremented depending on the type of transaction. In VFP I issued a Rlock() on the record, updated and then released it, how do I achieve this in SQL. Any help will be appreceiated.
>
>TIA


Fred,

The following works fine for me:

BEGIN TRANSACTION

UPDATE
MyTableName WITH (ROWLOCK) --this will lock all records affected
SET
MyColumn = MyColumn + MyNewValue
WHERE
PK = MyCondition

--read the UPDATED Content, at this point all other users have to wait
SELECT MyColumn FROM MyTableName WHERE PK = MyCondition


--release the lock
COMMIT TRANSACTION


--Aditionally, you can take a look at "SET TRANSACTION ISOLATION LEVEL" setting on the server
--Hope this helps
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform