How to calculate total storage space used by all databases in SQL Server

Hey everyone,

I’m trying to figure out the total disk space taken up by all the databases on my SQL Server 2000 instance. I’ve been searching for a while but can’t seem to find a good script or method to do this.

Does anyone know a reliable way to get this information? Maybe there’s a built-in function or a query I can run? I’m not super experienced with SQL Server, so any help would be awesome.

I’m mainly interested in:

  • The combined size of all databases
  • Including data files and log files
  • Preferably in GB or TB

Thanks in advance for any tips or solutions you can share!

For calculating total storage space across all databases in SQL Server, I suggest using the sp_spaceused stored procedure combined with a cursor. This approach lets you iterate through each database and aggregate their sizes. You can start by creating a temporary table to store the results, then loop through the databases, execute sp_spaceused on each, and insert the results into the temporary table. Finally, sum up the totals from the temporary table. This method accounts for both data and log files and works well even on older SQL Server versions. Ensure you have the necessary permissions to access all databases.

hey alex! have u tried using sys.master_files? it’s super helpful for this kinda stuff. you could write a query that sums up the size column for all databases. just make sure to convert the bytes to GB or TB. curious, why do u need this info? planning an upgrade or somethin?