Skip to content

Instantly share code, notes, and snippets.

@bh3605
Created April 2, 2021 15:11
Show Gist options
  • Save bh3605/630cb9f9e2bbd39cbbf4519fc0aa8df2 to your computer and use it in GitHub Desktop.
Save bh3605/630cb9f9e2bbd39cbbf4519fc0aa8df2 to your computer and use it in GitHub Desktop.
Returns a sql db server's signed in users
SELECT SESSION.login_name AS 'Database User Name'
,MAX(SESSION.login_time) AS 'Login Time'
,SESSION.host_name AS 'PC Name'
,SESSION.program_name AS 'Program Using'
,SESSION.client_interface_name AS 'Interface'
,UM.USER_NAME AS 'User'
FROM master.sys.dm_exec_Sessions SESSION
WHERE SESSION.session_id >= 51 -- All user Sessions
GROUP BY SESSION.login_name
,SESSION.host_name
,SESSION.program_name
,SESSION.client_interface_name
,UM.USER_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment