Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
How can I lock and unlock the table according to my requirements.

my application is performing transaction.
I need that till completion of my one transaction.no other one can perform any other transaction.or not see the select query result.

basically I want to know how to lock and unlock the table?
Posted

You need to be aware of SQL's isolation levels.

Secondly SQL by default uses locks for transaction isolation. This means that any queries that are executed against the server are held until the locks are released.

http://msdn.microsoft.com/en-us/library/ms173763.aspx[^]

As far as your application, If you are using ADO.NET for example you should take a look at this from MSDN:

http://msdn.microsoft.com/en-us/library/ms189542(v=sql.105).aspx[^]
 
Share this answer
 
TABLOCK - Use a table lock when reading or modifying data


UPDATE Products WITH (TABLOCK )
SET ProductCat = 'Machine';
WHERE ProductSubCat = 'Mac'';

For more information you can use this link-
http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/
 
Share this answer
 
http://msdn.microsoft.com/en-US/library/ms187373.aspx[^]

Here is the complete documentation about it.which can help in a batter way
 
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