Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Locking

Status
Not open for further replies.

notrut

Programmer
Feb 6, 2002
87
0
0
CA
How do you lock/unlock records in SQL. I want to prevent other users from updating/deleting records when the record is being accessed by someone else.
 
Hi,
Try this

select * from <table_name> with (tablock,updlock)

The above query will have the table level lock and update lock until the end of the statement or end of transaction.

For more hlep read locking, hints in BOL.

Madhu.
 
In order to provide any significant advice, we need to know how your application works. At what point do you want to lock rows? When the data is read? When the user does an update?

In my opinion, most applications should allow SQL Server to handle locking. I certainly advise against using tablock. That can make a system nearly unusable in a multi-user environment.

Check the following resources.

Understanding Locking in SQL Server

Customizing Locking with SQL Server

Dynamic Locking

Customizing Transaction Isolation Level

Transactions, locking and concurrency in SQL Server

Inside SQL Server: Controlling Locking
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top