The Following script will retrieve the size of all your databases in MB and GB.
SELECT d.NAME ,ROUND(SUM(CAST(mf.size AS bigint)) * 8 / 1024, 0) Size_MBs ,(SUM(CAST(mf.size AS bigint)) * 8 / 1024) / 1024 AS Size_GBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 -- Skip system databases GROUP BY d.NAME ORDER BY d.NAME
--Exclude Offline Databases
SELECT d.NAME
,ROUND(SUM(CAST(mf.size AS bigint)) * 8 / 1024, 0) Size_MBs
,(SUM(CAST(mf.size AS bigint)) * 8 / 1024) / 1024 AS Size_GBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4
--and d.state_desc='online' -- Skip system databases
GROUP BY d.NAME
ORDER BY d.NAME
No comments:
Post a Comment