top button
Flag Notify
Site Registration

What are the ways to find what code is running for any spid?

+4 votes
378 views
What are the ways to find what code is running for any spid?
posted Feb 21, 2014 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

A SPID in SQL Server is a Server Process ID. These process ID’s are essentially sessions in SQL Server. Everytime an application connects to SQL Server, a new connection (or SPID) is created. This connection has a defined scope and memory space and cannot interact with other SPIDs. The term SPID is synonymous with Connection, or Session

In order to view all the connections in SQL Server execute the following query.

SELECT *
FROM sys.dm_exec_sessions

To know which sessions are running currently, run the following command:

SELECT @@SPID
GO

In our case, we got SPID 105, which means the session that is running this command has ID of 105.

Let us run a simple SELECT statement in session with SPID 105 run the following command.

DBCC INPUTBUFFER(105)
GO
answer Feb 26, 2014 by Amit Kumar Pandey
...