Size of all databases on one SQL Server

Download PDF

Here is a script that I created to get the size of all of the databases on one SQL Server.

Generally I stay away from temp tables, especially global temp tables, but I didn’t see a good way to do this without them.

CREATE TABLE ##alldatabasesizes
  (
     dbname    VARCHAR(1024),
     type_desc VARCHAR(1024),
     name      VARCHAR(1024),
     size      INTEGER
  );
EXECUTE Sp_msforeachdb
'INSERT INTO ##AllDatabaseSizes 
SELECT db_name() as dbName, type_desc, 
name, size FROM [?].sys.database_files'

SELECT *
FROM   ##alldatabasesizes;
DROP TABLE ##alldatabasesizes

 

More from Stedman Solutions:

SteveStedman5
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

Leave a Reply

Your email address will not be published. Required fields are marked *

*