Common SQL Server Troubleshooting Queries

Last Query for All Open Connections (source):

SELECT    *
FROM    sys.dm_exec_requests er    
CROSS APPLY    sys.dm_exec_sql_text(er.sql_handle) AS t

Number of Open Connections (source):

SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame

Running Queries (Source):

SELECT sqltext.TEXT, req.session_id, req.status, req.command, req.cpu_time, req.total_elapsed_time 
FROM sys.dm_exec_requests req 
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

Kill Query (Source)

Kill {id}

This entry was posted in SQL Server. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.