Last active
August 29, 2015 13:56
-
-
Save pradeep1288/9198888 to your computer and use it in GitHub Desktop.
Gets the size of all the databases on a given sql server instance. (Credits: http://goo.gl/4aw6Al)
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
SELECT @@SERVERNAME AS SqlServerInstance, | |
db.name AS DatabaseName, | |
SUM(CASE WHEN af.groupid = 0 THEN 0 ELSE 8192.0E * af.size / 1048576.0E END) AS DatabaseSize, | |
SUM(CASE WHEN af.groupid = 0 THEN 8192.0E * af.size / 1048576.0E ELSE 0 END) AS LogSize, | |
SUM(8192.0E * af.size / 1048576.0E) AS TotalSize | |
FROM master..sysdatabases AS db | |
INNER JOIN master..sysaltfiles AS af ON af.[dbid] = db.[dbid] | |
WHERE db.name NOT IN('distribution', 'Resource', 'master', 'tempdb', 'model', 'msdb') | |
GROUP BY db.name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment