Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Hanging Process - SPID Query

How do I find what is the associated query that is being executed if I have the SPID. Trying to figure out what query is being associated since the process seems to be hung.

like image 234
Chris Avatar asked Mar 04 '11 19:03

Chris


People also ask

Why is my SPID suspended?

Suspended just means that the SPID is waiting for a resource, such as a page to be read from disk into memory. When a SPID is suspended, the reason it is waiting is logged as a wait event. Runnable means the SPID is waiting for an available scheduler, usually called a processor or CPU.

What is the use of @@ SPID?

@@SPID (Transact-SQL)Returns the session ID of the current user process.


1 Answers

--Find Current SQL Statements that are Running
SELECT   SPID           = er.session_id
        ,STATUS         = ses.STATUS
        ,[Login]        = ses.login_name
        ,Host           = ses.host_name
        ,BlkBy          = er.blocking_session_id
        ,DBName         = DB_Name(er.database_id)
        ,CommandType    = er.command
        ,ObjectName     = OBJECT_NAME(st.objectid)
        ,CPUTime        = er.cpu_time
        ,StartTime      = er.start_time
        ,TimeElapsed    = CAST(GETDATE() - er.start_time AS TIME)
        ,SQLStatement   = st.text
FROM    sys.dm_exec_requests er
    OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
    LEFT JOIN sys.dm_exec_sessions ses
        ON ses.session_id = er.session_id
    LEFT JOIN sys.dm_exec_connections con
        ON con.session_id = ses.session_id
WHERE   st.text IS NOT NULL
like image 92
user2661347 Avatar answered Oct 02 '22 05:10

user2661347