Disable or Enable all indexes

This script disabled all nonclusterd indexes. This can be useful for ETL processes.

-- disable all nonclustered indices
SET DEADLOCK_PRIORITY HIGH

DECLARE @DisableIndexen NVARCHAR(max);

DECLARE cur_rebuild CURSOR FOR 
   SELECT 'ALTER INDEX ' +  QUOTENAME(i.name) + ' ON ' + QUOTENAME(t.name) + ' DISABLE' 
   FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id 
   WHERE I.type_desc = 'NONCLUSTERED' and i.is_disabled = 0 ORDER BY t.name, i.name;
OPEN cur_rebuild;
FETCH NEXT FROM cur_rebuild INTO @DisableIndexen;
WHILE @@FETCH_STATUS = 0
   BEGIN
 --  print @DisableIndexen
     EXECUTE sp_executesql  @DisableIndexen;
      FETCH NEXT FROM cur_rebuild INTO @DisableIndexen;
   END;
CLOSE cur_rebuild;
DEALLOCATE cur_rebuild;

With this script you can enable the disabled indexes

-- enable all nonclustered indices
SET DEADLOCK_PRIORITY HIGH

DECLARE @RebuildIndexen NVARCHAR(200);

DECLARE cur_rebuild CURSOR FOR 
   SELECT 'ALTER INDEX ' +  QUOTENAME(i.name) + ' ON ' + QUOTENAME(t.name) + ' REBUILD' 
   FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id 
   WHERE i.is_disabled = 1 ORDER BY t.name, i.name;
OPEN cur_rebuild;
FETCH NEXT FROM cur_rebuild INTO @RebuildIndexen;
WHILE @@FETCH_STATUS = 0
   BEGIN
      EXECUTE sp_executesql  @RebuildIndexen;
      FETCH NEXT FROM cur_rebuild INTO @RebuildIndexen;
   END;
CLOSE cur_rebuild;
DEALLOCATE cur_rebuild;