How to find user process in MS SQL Server

You can get all running processes on a SQL Server by running "SP_who2" a system stored procedure, it will return all processes, however below query will give you options to fetch only user process and it gives you option to filter. You can tweak this query and get the desired result. The procedure "SP_who2" and below query will help you identify long running queries, blocking queries, active or inactive sessions.

DROP TABLE #sp_who2
CREATE TABLE #sp_who2 (SPID INT,Status VARCHAR(255),
Login  VARCHAR(255),HostName  VARCHAR(255), 
BlkBy  VARCHAR(255),DBName  VARCHAR(255), 
Command VARCHAR(255),CPUTime INT, 
DiskIO INT,LastBatch VARCHAR(255), 
ProgramName VARCHAR(255),SPID2 INT, 
REQUESTID INT) 
INSERT INTO #sp_who2 EXEC sp_who2
GO
select * from #sp_who2
where spid>50;

Comments

Popular posts from this blog

How to Enable / Disable a user in MS SQL Server

How to Create a Database in MS SQL Server