Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to unlock the table


How to unlock the table

Author
Message
changbluesky
changbluesky
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 150
Here I have a table locked by another process, so I cannot access it. I try writing a T-SQL to find the lucked or blocked process id and kill it. But seems that the query result column [A.blocked ] do not show the ture situation(always return 0). In this way I cannot find the lucked spid.

select   B.name,   A.cmd,   A.spid,A.blocked   from   master..sysprocesses  A   
join master..sysdatabases B on A.dbid = B.dbid
where B.name = DB_NAME()



Any friends have better idea? Go a step further, is it possible to find the lucked table?
Thanks!:-P
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47212 Visits: 44368
Don't use sysprocesses, it's deprecated, included only for backward comparability and will be removed in a future version.
Use sys.dm_exec_requests and/or sys_dm_tran_locks.

The way to 'unlock' a table is to kill the connection holding the lock, or wait for that connection to finish what it's doing and let SQL release the locks.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


dmoldovan
dmoldovan
Old Hand
Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)

Group: General Forum Members
Points: 382 Visits: 1454
You can also check the "processes" section of the activity monitor. Right click on the server in the object explorer and choose "activity monitor".
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search