?
Solved

how to lock and unlock a table exclusively?

Posted on 2012-04-05
4
Medium Priority
?
2,915 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

839 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