Solved

how to lock and unlock a table exclusively?

Posted on 2012-04-05
4
2,619 Views
Last Modified: 2012-04-05
hello group,

I have gone over few articles and samples on the web and learned something about locking a table and it types. However, not sure why I cannot find a solid answer on how to unlock a table.

my assumption was that unlock must be the answer but it doesn't work in sql server (I'm using 2008 R2). so far I have locked a table (exclusively since need to avoid any read/write on table):

USE DB1
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
SELECT 1 FROM test WITH (tablockx)
GO

Open in new window


eventually I had to kill the server process id after finding process id with kill command. now, question is what is the best and graceful to exit from lock state?

Thanks.
0
Comment
Question by:akohan
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37813019
You should COMMIT or ROLLBACK the transaction.
0
 

Author Comment

by:akohan
ID: 37813022
I tried and noticed COMMIT will work properly but is this a good and optimized approach (considering code above and commit)?

Regards.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 100 total points
ID: 37813030
Yes, that's the only approach to release the locks (i.e. issue a COMMIT or a ROLLBACK).
0
 

Author Closing Comment

by:akohan
ID: 37813062
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now