Skip to main content
Skip table of contents

What is SQL Server Executing Now?

When you want to verify what MS SQL Server is doing right now:

  • Open SSMS and connect to the desired SQL instance

  • Right-click the instance name → New Query

  • Copy and paste the code below on the right panel:

SQL
SELECT      
    DB_NAME(database_id) [DB_Name],
    Status,
    SUBSTRING(sql.text,(req.statement_start_offset/2)+1,
    CASE WHEN statement_end_offset=-1 OR statement_end_offset=0
        THEN (DATALENGTH(sql.Text)-req.statement_start_offset/2)+1
        ELSE (req.statement_end_offset-req.statement_start_offset)/2+1
        END) [SQL Statement],
    Command,
    Wait_Type,
    req.Start_Time,
    Session_ID,
    Wait_Time,
    Wait_Resource
FROM        
    sys.dm_exec_requests req OUTER APPLY 
    sys.dm_exec_sql_text(sql_handle) sql
WHERE       
    Session_ID > 50    -- Ignore system queries
    -- AND DB_NAME(database_id)='DatabaseName'  -- ADD FILTER IF DESIRED
ORDER BY    
    req.Start_Time
  • Click Execute of F5 (multiple times as needed).

  • To investigate a line from the report above (see screenshot example below): right-click the desired SQL Statement on the SSMS Results Grid report → Copy → Paste into a Notepad

Example

Keywords: Query, Queries, Performance, MS SQL Server, Doing Now, Frozen, SQK Locked query statement

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.