Find the size of all databases at once  

Posted by Sandesh Segu in , , ,

Twit This! Share this in Google Reader Share/Save/Bookmark Subscribe

You may run into cases where you have to find the size of all the databases in a server in less time...
This will be easy and quick when you have less databases on the box.
What happens if the box has more number of databases??? Here is a quick solution for it...

Run the below Query and get your results in less time and in one shot.

EXEC sp_msforeachdb 'Use ?

Declare @dbsize float
Declare @logsize float
select @dbsize = sum(convert(bigint,case when status & 64 = 0 then size else 0 end))
, @logsize = sum(convert(bigint,case when status & 64 <> 0 then size else 0 end))
from dbo.sysfiles
select ltrim(str((convert (dec (15,2),@dbsize) + convert (dec (15,2),@logsize))
* 8192 / 1048576,15,2) + '' MB'') AS [Size of ?]'

This entry was posted on Sunday, May 24, 2009 at Sunday, May 24, 2009 and is filed under , , , . You can follow any responses to this entry through the comments feed .

0 comments

Post a Comment

Place Your Ad Here

To Block this Place for your ad Contact Me @

Contact Me

Visitors