Index Maintenance Query, Rebuid (>40)or Reorganize (>10)

Below query will generated list of indexes to be re organized or rebuild based on 10-40 Rule. >=40 % Rebuild >=10 and <40 ReOrganize — This query is tested on working fine.       SELECT ‘ALTER INDEX [‘ + ix.name + ‘] ON [‘ + s.name + ‘].[‘ + t.name + ‘] ‘ +        CASE WHEN ps.avg_fragmentation_in_percent >= 40 THEN ‘REBUILD’ ELSE ‘REORGANIZE’ END +        CASE WHEN pc.partition_count > 1 THEN ‘ PARTITION = ‘ + cast(ps.partition_number as nvarchar(max)) ELSE ” END FROM   sys.indexes AS ix   INNER JOIN sys.tables t  ON t.object_id = ix.object_id        INNER JOIN… Read more