[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Showing who has a table locked

theredmiata@hotmail.com

3/22/2007 11:04:00 PM

All,

I've been playing around with various forms of the sp_who2 script
which shows quite a bit of current SQL activity. What I am now looking
to accomplish is to show given a table name, who has this table locked
and who is waiting to lock this table?

Any help would be appreciated...

Ian in San Diego

3 Answers

Codeman

3/23/2007 12:53:00 AM

0



"theredmiata@hotmail.com" wrote:

> All,
>
> I've been playing around with various forms of the sp_who2 script
> which shows quite a bit of current SQL activity. What I am now looking
> to accomplish is to show given a table name, who has this table locked
> and who is waiting to lock this table?
>
> Any help would be appreciated...
>
> Ian in San Diego
>
>

This should be a good start:

Select
tb.[Name] As [TableName],
Case (lk.req_Status)
When 1 Then 'Granted'
When 2 Then 'Converting'
When 3 Then 'Waiting'
End [LockStatus],
pr.loginame As [LoginName],
pr.nt_domain As [Domain],
pr.nt_username As [UserName]
From
sys.syslockInfo lk
Inner Join
sys.Tables tb
On lk.rsc_objid = tb.Object_ID
Inner Join
sys.sysProcesses pr
On pr.spid = lk.req_spid
Where
tb.[Name] = '<TableName>'


Hari

3/23/2007 1:28:00 AM

0

Hello,

Take a look into sys.dm_tran_locks dmv

Thanks
Hari

<theredmiata@hotmail.com> wrote in message
news:1174604631.131522.295220@y66g2000hsf.googlegroups.com...
> All,
>
> I've been playing around with various forms of the sp_who2 script
> which shows quite a bit of current SQL activity. What I am now looking
> to accomplish is to show given a table name, who has this table locked
> and who is waiting to lock this table?
>
> Any help would be appreciated...
>
> Ian in San Diego
>


Tony Rogerson

3/23/2007 8:16:00 AM

0

If you are using SQL Server 2005 then check out BLOCKED_PROCESS_REPORT and
how to use it (I'll blog about it soon).

It's a wonderful feature - the XML you get back from the event when fired
gives the SQL on both sizes of the block - the SQL from who's running and
the SQL from who's blocking.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/to... (Ramblings from the field from a
SQL consultant)
http://sqlser... (UK SQL User Community)


<theredmiata@hotmail.com> wrote in message
news:1174604631.131522.295220@y66g2000hsf.googlegroups.com...
> All,
>
> I've been playing around with various forms of the sp_who2 script
> which shows quite a bit of current SQL activity. What I am now looking
> to accomplish is to show given a table name, who has this table locked
> and who is waiting to lock this table?
>
> Any help would be appreciated...
>
> Ian in San Diego
>