Created
February 6, 2015 15:27
-
-
Save jeremypage/f3e6e2eb9a8c3ed8e7a7 to your computer and use it in GitHub Desktop.
Query connected users on SQL Server databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT @@ServerName AS SERVER | |
,NAME | |
,login_time | |
,last_batch | |
,getdate() AS DATE | |
,STATUS | |
,hostname | |
,program_name | |
,nt_username | |
,loginame | |
FROM sys.databases d | |
LEFT JOIN sysprocesses sp ON d.database_id = sp.dbid | |
WHERE database_id NOT BETWEEN 0 | |
AND 4 | |
AND loginame IS NOT NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment