sqlserver數(shù)據(jù)庫獲取數(shù)據(jù)庫信息
來源:易賢網(wǎng) 閱讀:1292 次 日期:2014-05-12 15:35:31
溫馨提示:易賢網(wǎng)小編為您整理了“sqlserver數(shù)據(jù)庫獲取數(shù)據(jù)庫信息”,方便廣大網(wǎng)友查閱!

MS SQL SERVER 獲取當前數(shù)據(jù)庫文件等信息,適用于多個版本:

代碼如下:

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上,執(zhí)行結果是:

代碼如下:

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

更多信息請查看IT技術專欄

更多信息請查看數(shù)據(jù)庫
易賢網(wǎng)手機網(wǎng)站地址:sqlserver數(shù)據(jù)庫獲取數(shù)據(jù)庫信息

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)