I have MS SQL 2008 R2, 500 databases. What is the most efficient, easiest and \'modern\' way to query all databases sizes.
The output should have columns:
Not to steal your answer and adapt it for points or anything, but here is another factorization:
select d.name,
sum(m0.size*8.0/1024) data_file_size_mb,
sum(m1.size*8.0/1024) log_file_size_mb
from sys.databases d
inner join sys.master_files m0 on m0.database_id = d.database_id
inner join sys.master_files m1 on m1.database_id = d.database_id
where m0.type = 0 and m1.type = 1
group by d.name, d.database_id
order by d.database_id