Query for the Size of All Databases in SQL

If you need to see the size of all databases on an SQL server, here is a helpful query, one I always seem to need to write by memory:

SELECT d.name AS Name,
(SUM(mf.size) * 8 / 1024 / 1024) AS Size_GB
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

 

Leave a Reply