Solved

how to lock and unlock a table exclusively?

Posted on 2012-04-05
4
2,596 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
Comment Utility
You should COMMIT or ROLLBACK the transaction.
0
 

Author Comment

by:akohan
Comment Utility
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
Comment Utility
Yes, that's the only approach to release the locks (i.e. issue a COMMIT or a ROLLBACK).
0
 

Author Closing Comment

by:akohan
Comment Utility
Thank you!
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

763 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

7 Experts available now in Live!

Get 1:1 Help Now