SQL Server 2008: How to query all databases sizes?

后端 未结 15 981
伪装坚强ぢ
伪装坚强ぢ 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:48

    All this examples work fine on most of my database servers. However if you have 1 server with multiple instances and all those servers those query's give you no result.

    For instance the first query gives a result like:

    name    DataFileSizeMB  LogFileSizeMB
    master  NULL    NULL
    tempdb  NULL    NULL
    model   NULL    NULL
    msdb    NULL    NULL
    

    So the databases are selected from sys.databases, however the table sys.master_files seems to be empty or gives no result.

    Even a simple query as select * from sys.master_files has a result of 0 records. You don't receive any errors but no records are found. On my servers with only 1 database instance this works fine.

提交回复
热议问题