Created
September 13, 2022 20:56
-
-
Save gwalkey/763d214febb8bf2601b6d32380d02beb to your computer and use it in GitHub Desktop.
SQL Server - Connections Per Database
This file contains 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
--- Simple | |
SELECT | |
@@SERVERNAME AS 'Server', | |
DB_NAME(dbid) as 'Database', | |
COUNT(dbid) as 'Number Of Open Connections' | |
FROM | |
sys.sysprocesses | |
WHERE | |
dbid > 0 | |
GROUP BY | |
dbid | |
with rollup | |
order by | |
2 | |
--- Detailed | |
SELECT | |
@@SERVERNAME AS 'Server', | |
sd.name DBName, | |
sp.dbid, | |
loginame [Login], | |
hostname, | |
[program_name] 'Program Name', | |
[spid], | |
last_batch LastBatch, | |
blocked BlkBy, | |
sp.[status], | |
cmd Command, | |
cpu CPUTime, | |
physical_io DiskIO | |
FROM sysprocesses sp | |
JOIN sysdatabases sd ON sp.dbid = sd.dbid | |
where sp.loginame<>'sa' | |
ORDER BY 2, 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment