Disable all indexes on a table in SQL Server

DECLARE @sql AS VARCHAR(MAX)='';

SELECT @sql = @sql + 
'ALTER INDEX ' + sys.indexes.name + ' ON  ' + sys.objects.name + ' DISABLE;' +CHAR(13)+CHAR(10)
FROM 
    sys.indexes
JOIN 
    sys.objects 
    ON sys.indexes.object_id = sys.objects.object_id
WHERE sys.indexes.type_desc = 'NONCLUSTERED'
  AND sys.objects.type_desc = 'USER_TABLE'
  AND sys.objects.object_id = object_id('[dbo].[TABLE_NAME]');


PRINT(@sql);
--EXEC(@sql);
Copied!

Use your own input

If you have values you'd like to use instead of the provided variables, type or paste your data into the variable inputs below. If Javascript is enabled, your text will automatically be added to the command and you can click to copy.