Disk utilization summary for all databases using SSMS

How can I see all disk usage by all my databases on a given SQL Server in one query. I have about 15 different databases on my server, and I want to see which one uses the maximum disk space.

I know that I can see disk usage reports for each database in SSMS or log in to the server and see the size of the MDF / LDF files, but this seems like a pretty obvious function that should come with SSMS, and I cannot find it.

+5
source share
2 answers

I don’t know any built-in methods, but you can use a procedure (undocumented) sp_MSforeachdbto do this.

CREATE TABLE #files(
    [dbname] [sysname] NOT NULL,
    [name] [sysname] NOT NULL,
    [physical_name] [nvarchar](260) NOT NULL,
    [size] [int] NOT NULL,
    [max_size] [int] NOT NULL,
    [growth] [int] NOT NULL
)

EXEC sp_MSforeachdb ' 
insert into #files
select ''[?]'',name,physical_name,size,max_size,growth
from [?].sys.database_files'


SELECT [dbname]
      ,[name]
      ,[physical_name]
      ,[size]
      ,[max_size]
      ,[growth]
  FROM #files
+8
source

This stored procedure will help.

exec sp_helpdb;

You will get something like this:

name      db_size       owner         dbid created     status                                                                                                                                                                                                                                                                          compatibility_level
--------- ------------- ------------- ---- ----------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
Database1    7262.81 MB DOMAIN\Admin  5    Aug 25 2010 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics                                                                             100
Project27   22781.81 MB DOMAIN\User42 13   Oct 13 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAnsiNullsEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsQuotedIdentifiersEnabled 100
MyDBName       84.69 MB DOMAIN\Me     14   Oct 14 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabled                                                          100

To learn more about a specific database, follow these steps:

exec sp_helpdb DatabaseName;
+6
source

All Articles