Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Enable/Disable all indexes in all tables at once


Enable/Disable all indexes in all tables at once

Author
Message
ALIF-662928
ALIF-662928
SSC Eights!
SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)SSC Eights! (843 reputation)

Group: General Forum Members
Points: 843 Visits: 758
Hi,

Does any one have a script to ENABLE and DISABLE all the Indexes for all the Tables of a particular database on sql server 2005.
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22924 Visits: 18262
ALIF-662928 (3/3/2010)
Hi,

Does any one have a script to ENABLE and DISABLE all the Indexes for all the Tables of a particular database on sql server 2005.



To disable

select 'alter index ' +i.name+ ' on ' +o.name+ ' disable ' + CHAR(13)+Char(10)+';'
From sys.indexes i
Inner Join sys.objects o
On o.object_id = i.object_id
Where o.is_ms_shipped = 0
And i.index_id >= 1



To enable - REBUILD the indexes.

Article to read:
http://www.sqlservercentral.com/articles/Indexing/63533/



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Sarab_SQLGeek
Sarab_SQLGeek
SSC-Addicted
SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)

Group: General Forum Members
Points: 420 Visits: 558
You can use the undocumented procedure described here:
http://solutions-guru.com/articles/sql-server/86-undocumented-procedure-spmsforeachtable-a-spmsforeachdatabase.html

Regards,
Sarabpreet Singh Cool
Sarabpreet.com
SQLChamp.com
Twitter: @Sarab_SQLGeek
Joshua Feierman
Joshua Feierman
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 304
Edit: DOH, I didn't see this thread was quite old, for some reason it came up in my feed on the site home page. Oh well, still relevant certainly!

Hi there, I actually just published an article describing exactly how to do this, with a stored procedure that wraps up all the necessary logic.

http://www.sqlservercentral.com/articles/Maintenance+and+Management/131604/

Let me know if this works for you or if you can think of anything that would make it better!

Senior DBA - Gateway Ticketing Systems
Co-Founder - Do It Simply Software

Follow me at http://sqljosh.com
johnwalker10
johnwalker10
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 289
Script to disable index:
ALTER Index indexname ON tablename.columnname DISABLE;


Script to enable index:
ALTER  Index indexname ON tablename.columnname REBUILD; 



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search