SQL Snippet – list all databases with size

SQL Snippet – list all databases with size
1 vote, 5.00 avg. rating (95% score)

SQL – Get the list of all the databases and their size

The below script will give the list of all database with name and size of respective database

 SELECT d.name [DB Name],
 ROUND(SUM(mf.size) * 8 / 1024, 0) [DB Size (Mb)] 
FROM sys.master_files mf 
INNER JOIN sys.databases d ON d.database_id = mf.database_id
 WHERE d.database_id > 4 -- avoid system databases 
GROUP BY d.name ORDER BY [DB Size (Mb)] desc 

Output

image

January 26, 2015 В· Adi В· No Comments
Posted in: Code Snippet, SQL

Leave a Reply

What is 6 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)