Andrew Peterson has a script to grab space used for each database:
After reviewing the posts, many, perhaps all of the procedures and commands I found provided valuable information. Just not what I wanted. We have:
sp_spaceused, but it returns data in two data sets. Not ideal. Next we have…
sp_databases, but it just returns a list of databases and the size. Not ideal. Or use…
DBCC showfilestats, Ok, but still incomplete. And, since it is not listed on the main DBCC page at MSDN, its most likely deprecated.
And speaking of DBCC, there are other commands to consider. But what I was really hoping to find was a simple way to use the sys.database_files DMV. It is very close, but not quite complete.
Read on for the solution. One small change I’d prefer is using Aaron Bertrand’s sp_foreachdb for iterating. Or write a Powershell script if you want to take the looping outside of SQL Server.