sqlserver数据库获取数据库信息

栏目: 数据库 · SQL Server · 发布时间: 7年前

内容简介:这篇文章主要介绍了sqlserver数据库获取数据库文件信息,大家参考使用吧

MSSQL 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  
    , CAST(CAST(FILEPROPERTY(dbf.name, 'SpaceUsed') AS int)/128.0 AS
DECIMAL(19,2)) AS SpaceUsedMB  
    , CAST(dbf.size/128.0 - CAST(FILEPROPERTY(dbf.name, 'SpaceUsed') AS
int)/128.0 AS DECIMAL(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 上,执行结果是:

代码如下:

XXX_standard_data  
D:\Program
Files\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\DATA\wolf_wanzheng.mdf
2000.00    1286.38    713.63    35.68    0    PRIMARY  
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  
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  
 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  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Ordering Disorder

Ordering Disorder

Khoi Vinh / New Riders Press / 2010-12-03 / USD 29.99

The grid has long been an invaluable tool for creating order out of chaos for designers of all kinds—from city planners to architects to typesetters and graphic artists. In recent years, web designers......一起来看看 《Ordering Disorder》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具