Click here to Skip to main content
15,887,683 members
Articles / Database Development / SQL Server / SQL Server 2008
Tip/Trick

SQL Server: Get All Databases Size

Rate me:
Please Sign up or sign in to vote.
4.43/5 (5 votes)
2 Oct 2012CPOL 103.8K   5   1
A simple query to get all databases size on a given instance.

Introduction

To get recent size of all databases on an instance, I have found following simple query very useful.

Script

SQL
SELECT d.name,
ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader CureMD
Pakistan Pakistan
Aasim Abdullah is working as SQL Server DBA with CureMD (www.curemd.com) based in NY, USA. He has been working with SQL Server since 2007 (Version 2005) and has used it in many projects as a developer, administrator, database designer. Aasim's primary interest is SQL Server performance tuning. If he finds the time, he like to sketch faces with graphite pencils.

Comments and Discussions

 
QuestionDB size from a list of servers Pin
Member 1042182630-Jan-14 17:58
Member 1042182630-Jan-14 17:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.