Solved

how to lock and unlock a table exclusively?

Posted on 2012-04-05
4
2,745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

717 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