SQL SERVER 2008 R2查询需要优化的表碎片

 SELECT dbschemas.[name] as 'Schema',     
    dbtables.[name] as 'Table',     
    dbindexes.[name] as 'Index',     
    indexstats.avg_fragmentation_in_percent,     
    indexstats.page_count     
    FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats     
    INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]     
    INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]     
    INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
     
    AND indexstats.index_id = dbindexes.index_id     
    WHERE indexstats.database_id = DB_ID()     
    ORDER BY indexstats.avg_fragmentation_in_percent desc

查询需要优化的表碎片

When the avg_fragmentation_in_percent >30, please rebuild the index (alter index rebuild). If the 5 < avg_fragmentation_in_percent < 30, please reorgnize the index (alter index reorganize)

 

However, as you mentioned that it finished quickly, maybe you can manage it before you run the job each time. Just arrange it as the preparation for you job. Please update statistics each time you want to run the job.

转载于:https://www.cnblogs.com/shuzehui/p/10149660.html

发布了47 篇原创文章 · 获赞 5 · 访问量 3万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章