What is the best way to determine what's locking up SQL Server using a query?

Posted by Aplato on Server Fault See other posts from Server Fault or by Aplato
Published on 2011-02-24T16:01:13Z Indexed on 2011/02/24 23:27 UTC
Read the original article Hit count: 242

Recently our SQL Server is getting bogged down by something. I was wondering what is the best way to check what could be causing the problem by querying the database. This is the best I've found so far:

SELECT
    SPID            = s.spid
,   BlockingSPID    = s.blocked
,   DatabaseName    = DB_NAME(s.dbid)
,   ProgramName     = s.program_name
,   [Status]        = s.[status]
,   LoginName       = s.loginame
,   ObjectName      = OBJECT_NAME(objectid, s.dbid)
,   [Definition]    = CAST([text] AS VARCHAR(MAX))
FROM      sys.sysprocesses s
CROSS APPLY sys.dm_exec_sql_text (sql_handle)
WHERE 
 s.spid > 50
ORDER BY
    DatabaseName
,   loginName

© Server Fault or respective owner

Related posts about sql

Related posts about sql-server