Home > Database > Mysql Tutorial > body text

SQL SERVER获取数据库文件信息

WBOY
Release: 2016-06-07 17:37:41
Original
1129 people have browsed it

SQL SERVER获取数据库文件信息 MS SQL SERVER 获取当前数据库文件等信息,适用于多个版本: SELECT dbf.file_id AS FileID , dbf.name AS [FileName] , s.filename AS FileLocation , CAST (dbf. size /128.0 AS DECIMAL (19,2)) AS FileSizeMB , (19,2)) AS

SQL SERVER获取数据库文件信息

    MS SQL SERVER 获取当前数据库文件等信息,适用于多个版本:

SELECT dbf.file_id AS FileID , dbf.name AS [FileName] , s.filename AS FileLocation , CAST(dbf.size/128.0 AS DECIMAL(19,2)) AS FileSizeMB , (19,2)) AS SpaceUsedMB , (19,2)) AS AvailableSpaceMB , CAST((dbf.size / 128.0 - (FILEPROPERTY(dbf.name, 'SpaceUsed') / 128.0)) / (dbf.size / 128.0) * 100 AS DECIMAL(19,2)) AS [%FreeSpace] , dbf.growth / 128 AS FileGrowthMB , f.name AS FilegroupName FROM sys.database_files dbf INNER JOIN sys.sysfiles s ON dbf.name = s.name LEFT JOIN sys.filegroups f ON dbf.data_space_id = f.data_space_id ORDER BY dbf.name;


例如我们在某个Database上,执行结果是:

1    XXX_standard_data   
D:\Program Files\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\DATA\wolf_wanzheng.mdf    2000.00    1286.38    713.63    35.68    0    PRIMARY
2    XXX_standard_log   
D:\Program Files\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\DATA\wolf_wanzheng_2.ldf    157.19    2.47    154.72    98.43    0    NULL
3    XXX_temp2_data   
D:\Program Files\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\DATA\wolf_wanzheng_1.ndf    500.00    0.06    499.94    99.99    0    temp2
4    XXX_temp2_log   
D:\Program Files\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\DATA\wolf_wanzheng_3.ldf    142.88    2.25    140.63    98.43    0    NULL

 

希望对您数据库管理有帮助,您可能感兴趣文章:

列出Server上5张最大的表
简单T-Sql备份所有数据库
更多分类


作者:Petter Liu
出处:
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog。

posted on

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template