Disable all non-clustered indexes

Posted by spender on Stack Overflow See other posts from Stack Overflow or by spender
Published on 2010-03-25T17:58:01Z Indexed on 2010/03/25 18:13 UTC
Read the original article Hit count: 376

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2008