sqlserver数据库获取数据库信息
程序员文章站
2023-11-04 19:55:22
ms sql server 获取当前数据库文件等信息,适用于多个版本: 复制代码 代码如下:select dbf.file_id as fileid ...
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
, 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
上一篇: cad怎样怎么绘制电脑液晶显示器平面图?
下一篇: 足利义辉是谁?征夷大将军足利义辉生平简介