Search This Blog

Friday, February 4, 2011

Check Blocking in Database

Here is the script;


Declare @vTable table(SPID int,[Status] nvarchar(256),Login nvarchar(256),HostName nvarchar(256),
BlkBy nvarchar(256),DBName nvarchar(256),Command nvarchar(max),CPUTime int
,DiskIO int,LastBatch nvarchar(256),ProgramName nvarchar(256),SPID1 int,REQUESTID int)

Insert into @vTable
        Exec sp_who2

Select SPID,Status,HostName,BlkBy as BlockBy, DBName, Command, CPUTime,DiskIO, ProgramName,objectid,text
from (Select a.sql_handle,b.* from sys.dm_exec_requests a
Inner Join @vTable b on b.SPID = a.session_ID) Main
cross apply sys.dm_exec_sql_text (Main.sql_handle)
where BlkBy <> ' .'

No comments:

Post a Comment