SQL Server: Find Currently running queries

We have SQL Server and 6 users are accessing same server. I just wanted to monitor quickly which queries are running currently. This T-SQL query helped me.

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

2 comments:

  1. This is an interesting post. I've been wondering about this topic, so thank you for sharing it. Great post.It's really a nice and useful post.Thanks. In the fantasy world, orcs are regarded as dumb beasts. They have green skin, are very fleshy and are much less intelligent than other races. They have difficult names. Use this article for help orc name generator. You will learn about the orc name here.

    ReplyDelete
  2. Your article contains vital information for me, so I am glad to see it. Although there are a few general things I should mention, the website style is excellent, and the content is excellent. I would also like to share with you How to Make your Mouse Click Faster, especially if you are a gamer. I have listed some simple tips below to help you improve your mouse CPS.

    ReplyDelete