使用 SSMS 的所有数据库的磁盘使用情况摘要

发布于 2024-09-18 07:15:53 字数 185 浏览 4 评论 0原文

如何在一个查询中查看给定 SQL Server 上所有数据库的所有磁盘使用情况。我的服务器上有大约 15 个不同的数据库,我想看看哪一个正在使用最大磁盘空间。

我知道我可以在 SSMS 中查看每个数据库的磁盘使用情况报告,或者登录到服务器并查看 MDF/LDF 文件的大小,但这似乎是 SSMS 附带的一个非常明显的功能,但我似乎找不到它。

How can I see all disk usage of all my databases on a given SQL Server in one single query. I have around 15 different databases on my server and I want to see which one is using the maximum disk space.

I know I can see reports of Disk Usage per database in SSMS or logon to the server and see the size of MDF/LDF files but this seems like a pretty obvious feature that should come with SSMS and I cant seem to find it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几味少女 2024-09-25 07:15:54

这个存储过程会有所帮助。

exec sp_helpdb;

您将得到如下信息:

name      db_size       owner         dbid created     status                                                                                                                                                                                                                                                                          compatibility_level
--------- ------------- ------------- ---- ----------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
Database1    7262.81 MB DOMAIN\Admin  5    Aug 25 2010 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics                                                                             100
Project27   22781.81 MB DOMAIN\User42 13   Oct 13 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAnsiNullsEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsQuotedIdentifiersEnabled 100
MyDBName       84.69 MB DOMAIN\Me     14   Oct 14 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabled                                                          100

要了解有关特定数据库的更多信息,请执行以下操作:

exec sp_helpdb DatabaseName;

This stored procedure will help.

exec sp_helpdb;

You'll get something like this:

name      db_size       owner         dbid created     status                                                                                                                                                                                                                                                                          compatibility_level
--------- ------------- ------------- ---- ----------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
Database1    7262.81 MB DOMAIN\Admin  5    Aug 25 2010 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics                                                                             100
Project27   22781.81 MB DOMAIN\User42 13   Oct 13 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAnsiNullsEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsQuotedIdentifiersEnabled 100
MyDBName       84.69 MB DOMAIN\Me     14   Oct 14 2011 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabled                                                          100

To learn more about a particular database, do:

exec sp_helpdb DatabaseName;
黯淡〆 2024-09-25 07:15:54

我不知道任何内置方式,但您可以使用(未​​记录的)sp_MSforeachdb 过程来实现此目的。

CREATE TABLE #files(
    [dbname] [sysname] NOT NULL,
    [name] [sysname] NOT NULL,
    [physical_name] [nvarchar](260) NOT NULL,
    [size] [int] NOT NULL,
    [max_size] [int] NOT NULL,
    [growth] [int] NOT NULL
)

EXEC sp_MSforeachdb ' 
insert into #files
select ''[?]'',name,physical_name,size,max_size,growth
from [?].sys.database_files'


SELECT [dbname]
      ,[name]
      ,[physical_name]
      ,[size]
      ,[max_size]
      ,[growth]
  FROM #files

I'm not aware of any built in way but you can use the (undocumented) sp_MSforeachdb procedure for this.

CREATE TABLE #files(
    [dbname] [sysname] NOT NULL,
    [name] [sysname] NOT NULL,
    [physical_name] [nvarchar](260) NOT NULL,
    [size] [int] NOT NULL,
    [max_size] [int] NOT NULL,
    [growth] [int] NOT NULL
)

EXEC sp_MSforeachdb ' 
insert into #files
select ''[?]'',name,physical_name,size,max_size,growth
from [?].sys.database_files'


SELECT [dbname]
      ,[name]
      ,[physical_name]
      ,[size]
      ,[max_size]
      ,[growth]
  FROM #files
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文