top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+4 votes
123 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...