Disable all non-clustered indexes
- by spender
I select a number of non-clustered indexes from my database with the following:
SELECT sys.objects.name tableName,
sys.indexes.name indexName
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'
I'd like to run the following over each of the results:
ALTER INDEX indexName ON tableName DISABLE
How would I go about doing this? Is there a better way?