首页 > 数据库 >SQLSserver数据文件碎片查看

SQLSserver数据文件碎片查看

时间:2023-01-31 09:49:09浏览次数:46  
标签:SQLSserver 数据文件 128.0 碎片 FileSize FreeSpaceMB FileName type desc

CREATE TABLE #FileSize
(dbName NVARCHAR(128), 
    FileName NVARCHAR(128), 
    type_desc NVARCHAR(128),
    CurrentSizeMB DECIMAL(10,2), 
    FreeSpaceMB DECIMAL(10,2)
);
    
INSERT INTO #FileSize(dbName, FileName, type_desc, CurrentSizeMB, FreeSpaceMB)
exec sp_msforeachdb 
'use [?]; 
 SELECT DB_NAME() AS DbName, 
        name AS FileName, 
        type_desc,
        size/128.0 AS CurrentSizeMB,  
        size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0 AS FreeSpaceMB
FROM sys.database_files
WHERE type IN (0,1);';
    
SELECT * 
FROM #FileSize
WHERE dbName NOT IN ('distribution', 'master', 'model', 'msdb')
-- AND FreeSpaceMB > 60
order by 5 desc;
    
DROP TABLE #FileSize;

  

标签:SQLSserver,数据文件,128.0,碎片,FileSize,FreeSpaceMB,FileName,type,desc
From: https://www.cnblogs.com/abclife/p/17077826.html

相关文章