SQL Server 2008: How to query all databases sizes?

后端 未结 15 1203
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  Happy的楠姐
    2021-01-29 18:53

    Here's a simple, quick and reliable query that will give all database and log file names, sizes and also database statuses (e.g. ONLINE) in a nice, easy to read output:

    SELECT
        D.name,
        F.Name AS FileType,
        F.physical_name AS PhysicalFile,
        F.state_desc AS OnlineStatus,
        CAST(F.size AS bigint) * 8*1024 AS SizeInBytes,
        CAST((F.size*8.0)/1024/1024 AS decimal(18,3)) AS SizeInGB
    FROM 
        sys.master_files F
        INNER JOIN sys.databases D ON D.database_id = F.database_id
    ORDER BY SizeInBytes desc
    

提交回复
热议问题