Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Total size of all databases on server?

Author  Topic 

thj
Starting Member

8 Posts

Posted - 2008-09-17 : 06:12:33
Hi.

I need to report the total size of all databases (including log), on all SQL servers in a domain.

How can I get the total size of all databases on a single server?

I've tryed "EXEC sp_MSforeachdb 'EXEC sp_spaceused'", and that kinda works but I need to sum all the sizes so I will get one number for the size of all databases.

Could someone help me do that?

Thanks in advance.
Tommy.

ranganath
Posting Yak Master

209 Posts

Posted - 2008-09-17 : 06:38:15

Hi,
try with this

EXEC sp_databases;
Go to Top of Page

thj
Starting Member

8 Posts

Posted - 2008-09-17 : 06:45:57
Thank you.

So now I've got this:

CREATE TABLE #server_databases (
DATABASE_NAME nvarchar(200),
DATABASE_SIZE int,
REMARKS nvarchar(200))

INSERT INTO #server_databases EXEC sp_databases

SELECT SUM(DATABASE_SIZE)/1024/1024 FROM #server_databases

DROP TABLE #server_databases


How can I do this for each server (stored in a table), and return server_name and total size?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-17 : 07:11:47
quote:
Originally posted by thj

Thank you.

So now I've got this:

CREATE TABLE #server_databases (
DATABASE_NAME nvarchar(200),
DATABASE_SIZE int,
REMARKS nvarchar(200))

INSERT INTO #server_databases EXEC sp_databases

SELECT SUM(DATABASE_SIZE)/1024/1024 FROM #server_databases

DROP TABLE #server_databases


How can I do this for each server (stored in a table), and return server_name and total size?


One method is to use SSIS package to loop through server names from table and use sql task to connect to each and calculate the size.
Go to Top of Page
   

- Advertisement -