views:

35

answers:

2

How can I see all disk usage of all my databases on a given SQL Server in one single query. I have around 15 different databases on my server and I want to see which one is using the maximum disk space.

I know I can see reports of Disk Usage per database in SSMS or logon to the server and see the size of MDF/LDF files but this seems like a pretty obvious feature that should come with SSMS and I cant seem to find it.

+3  A: 

I'm not aware of any built in way but you can use the (undocumented) sp_MSForEachDB procedure for 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
Martin Smith
+1:Yep, that's what I do.
John Sansom
Thanks! this works.
mvm
+1  A: 

Try this:

sp_helpdb
Emtucifor