There are many ways to know the Server Process id or now also known as Session ID (SPID). The most common methods are as follows:
1. Use global variable @@SPID
SELECT @@SPID as spid
2. Use Properties window
While working in the Query Analyzer, press F4. A Property Window opens and you can see SPID in the last row
3. Use System procedure sp_who
EXEC sp_who
The above will list out all the processes with spid. The last spid is the one related
to your session.
4. Use sysprocesses view
select spid from sys.sysprocesses
This query will list out all the processes with spid. The last spid is the one related
to your session.
3 comments:
I got this for your 4th method
SELECT @@SPID
Gets 65
Then the
select spid from sys.sysprocesses
The last was 78 :)
Looks like it is the second last row that has the SSID. I am not sure though.
Madhivanan, any inputs?
I think it may not gaurantee to give the id in the order we expect. sysprocesses will have the spid for the current session
Post a Comment