Question: Which SQL Server session belongs to SQL Server Management Studio?
Answer: This one was not asked by an interviewer. At the end of an interview I helped conduct, a candidate asked us how to find the SSMS sessions. I liked the question because the answer is practical: first identify your own query window, then look at the program names of the sessions you are allowed to see.

In the query window you are using right now, @@SPID gives that window’s session ID. Run this first so you have a value you can recognize in the wider list.
SELECT @@SPID AS ThisQueryWindowSessionId;The original answer used sp_who2 and pointed to its ProgramName column. The historical SSMS result below shows how to recognize the program name. The boxed entries are SSMS query sessions in that capture; your version and program names may differ.
EXEC sp_who2;
For a query you can sort and filter, use sys.dm_exec_sessions. The program_name value is the client program name recorded for each session; it is a helpful clue, not an authentication or security proof.
SELECT session_id,
login_name,
host_name,
program_name,
status,
login_time
FROM sys.dm_exec_sessions
WHERE is_user_process = 1
AND program_name LIKE N'Microsoft SQL Server Management Studio%'
ORDER BY session_id;If you have only permission to see your own session, the wider list will be limited. I still start with @@SPID when answering this in an interview: it connects the window in front of me to the session ID in the result.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.





7 Comments. Leave new
Current tab SPID is visible (or can be toggled – as visible – in Settings) directly in SSMS status bar.
Should be that “your login name (spid)”
This is also be identified via activity monitor , you would be able to see all the sessions , under application name you would see Microsoft SQL Server Management Studio.
sys.dm_exec_sessions was the first answer that came into my mind.
In this case program_name column has a value of ‘Microsoft SQL Server Management Studio’ or ‘Microsoft SQL Server Management Studio – Query’
The session id is included in the status bar at the bottom of SSMS itself :-)
Not really…
At bottom of SSMS you will only see the ID of Query Window which is open not for all the session id which SSMS consuming.
Yeah, there is at least one additional connection – for Object browser. But Usually this is best correct answer.
sp_who2 – nice, keep scrolling in 6000+ rows on production cluster :)
we can also try this to sys.dm_exec_sessions