SQL Server 2008: How to query all databases sizes?

后端 未结 15 975
伪装坚强ぢ
伪装坚强ぢ 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 18:47

    SELECT
        DB.name,
        SUM(CASE WHEN type = 0 THEN MF.size * 8 / 1024 ELSE 0 END) AS DataFileSizeMB,
        SUM(CASE WHEN type = 1 THEN MF.size * 8 / 1024 ELSE 0 END) AS LogFileSizeMB
    FROM
        sys.master_files MF
        JOIN sys.databases DB ON DB.database_id = MF.database_id
    GROUP BY DB.name
    ORDER BY DataFileSizeMB DESC
    

提交回复
热议问题