zoukankan      html  css  js  c++  java
  • 碎片批处理

     --推荐使用ACTION1,因为它支持在线操作,重建索引期间支持其他操作
     DECLARE @ACTION1 VARCHAR(MAX)
     DECLARE @ACTION2 VARCHAR(MAX)
     
     DECLARE pcurr CURSOR
     FOR
        SELECT  
                --objects.name ,
                --indexes.name AS indexid ,
                --avg_fragmentation_in_percent AS frag ,
                --partition_stats.row_count ,
                'ALTER INDEX ' + indexes.name + ' ON ' + objects.name
                + ' REBUILD  WITH (ONLINE = ON )' ACTION1 ,
                'ALTER INDEX ' + indexes.name + ' ON ' + objects.name
                + ' REORGANIZE WITH ( LOB_COMPACTION = ON ) ' ACTION2
        FROM    sys.dm_db_index_physical_stats(7, NULL, NULL, NULL, 'LIMITED') stats
                LEFT JOIN sys.objects objects ON stats.object_id = objects.object_id
                LEFT JOIN sys.indexes indexes ON indexes.index_id = stats.index_id
                                                 AND stats.object_id = indexes.object_id
                LEFT  JOIN sys.dm_db_partition_stats partition_stats ON stats.object_id = partition_stats.object_id
                                                                  AND indexes.index_id = partition_stats.index_id
        WHERE   avg_fragmentation_in_percent > 4
                AND stats.index_id > 0
                AND objects.name NOT IN ( 'Student_Delete_Apply' )
        ORDER BY row_count DESC ,
                avg_fragmentation_in_percent DESC
            

     OPEN pcurr

     FETCH NEXT FROM pcurr INTO @ACTION1, @ACTION2

     WHILE ( @@FETCH_STATUS = 0 )
        BEGIN
     
            EXEC  (@ACTION1)
            PRINT ( @ACTION1 )
           -- EXEC  (@ACTION2)
        ----------------------------
            FETCH NEXT FROM pcurr INTO @ACTION1, @ACTION2
        END

     CLOSE pcurr

     DEALLOCATE pcurr

  • 相关阅读:
    .NETCORE CONSUL
    Jenkins+github自动化部署.Net Core程序到Docker
    CleanArchitecture原则CQRS模式
    BFF架构了解
    .NET 生态系统的蜕变之 .NET 6
    Deislabs开源 使用WebAssembly打造的PaaS项目Hippo
    微软认真聆听了开源 .NET 开发社区的炮轰: 通过CLI 支持 Hot Reload 功能
    单体应用 适合采用 dapr 构建吗?
    微软发布了Visual Studio 2022 RC版,并将在11月8日发布正式版
    [LeetCode] 1248. Count Number of Nice Subarrays 统计优美子数组
  • 原文地址:https://www.cnblogs.com/qanholas/p/2426414.html
Copyright © 2011-2022 走看看