sqlserver 查询数据库大小的方法
编程学习 2021-07-05 13:42www.dzhlxh.cn编程入门
总部要求每一个月,获取一次ERP数据库增长大小。我收到的样版是一张截图,是直接查看数据库文件大小
但Insus.NET想到的是,从狼蚁网站SEO优化的SQL语句,就可以查询到数据库大小。因此分享于此。
SELECT DB_NAME(database_id) AS [Database Name],[Name] AS [Logical Name],[Physical_Name] AS [Physical Name],((size * 8) / 1024) AS [Size(MB)],[differential_base_time] AS [Differential Base Time]
FROM sys.master_files
WHERE DB_NAME(database_id) IN('XXX')
GO
代码如下:
SELECT DB_NAME(database_id) AS [Database Name],[Name] AS [Logical Name],[Physical_Name] AS [Physical Name],((size * 8) / 1024) AS [Size(MB)],[differential_base_time] AS [Differential Base Time]
FROM sys.master_files
WHERE DB_NAME(database_id) IN('XXX')
GO