SQL Server 2008: How to query all databases sizes?

后端 未结 15 1247
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 18:08

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:

15条回答
  •  死守一世寂寞
    2021-01-29 19:06

    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
    

提交回复
热议问题