Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my multiuser database, the statements within multiple simultaneous transactions can update the same data in a table. I have to restrict access of data until one transactions gets complete

What I have tried:

I had heard about Data Concurrency & Consistency but could not understand
Posted
Updated 12-Oct-18 7:59am
Comments
pradiprenushe 12-Oct-18 1:25am    
Read about transaction and isolation level.
navidshaikh0702 12-Oct-18 1:37am    
Appreciate your solution!!!

It's extremely rare that you would need to do that, but there are at least a couple of options.

1) Lock the entire table with TABLOCKX:
If you are in a transaction and you grab an exclusive lock on a table, EG:
SELECT 1 FROM TABLE WITH (TABLOCKX)
No other processes will be able to grab any locks on the table, meaning all queries attempting to talk to the table will be blocked until the transaction commits.

2) Use manual application locks:
sp_getapplock (Transact-SQL) | Microsoft Docs[^]
sp_releaseapplock (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 
This WITH (NOLOCK) example[^] should give you an idea about how to go for locking the tables.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900