5

I was wondering if there is a sql statement to get the current size of all the databases on your server instead of right clicking and going to properties for each one.

4 Answers 4

6

If you can use stored procedures, this should work:

exec sp_msforeachdb 'use ? exec sp_spaceused'
1
  • Although this will give back a resultset for each of the databases which looks a bit messy. I prefer to use my answer which gives a nice table.
    – pjp
    Sep 23, 2009 at 12:16
4

Check out the sys.master_files table.

This query will give you total size of everything in your instance:

SELECT SUM(size*8192.0) AS totalsize
FROM sys.master_files;
2

The simplest way is to use:

exec [sys].[sp_databases]
go

Which produces something like:

Name        Size  Remarks
mydatabase1 29888 NULL
mydatabase2 13760 NULL
mydatabase3 11776 NULL
master      5376  NULL
model       3008  NULL
msdb        7616  NULL
tempdb      2560  NULL

For the size of the transaction logs associated with a database, use:

dbcc sqlperf(logspace)
go

Which produces something like:

Name        Log Size (MB) Log Space Used (%) Status
master      1.242188      50.9434            0
tempdb      0.7421875     61.25              0
model       0.7421875     38.94737           0
msdb        1.992188      35.88235           0
mydatabase1 5.554688      18.55661           0
mydatabase2 2.742188      32.9594            0
mydatabase3 8.992188      26.58015           0
1
  • hey thomas, is there a way to format the ouput of the first query in MB directly? thank you very much! Aug 27, 2014 at 12:15
2
exec sp_helpdb

Lists out the size of data, owner, creation date, etc for all databases on a server in one nice table.

If you then want to go delving into a particular database to see the individual table sizes you can use

use MyFunkyDb
go
EXECUTE sp_MSforeachtable 'EXECUTE sp_spaceused [?]'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.