Rebuild or Reorganize All indexes in all the database

  • hi there

    i want to write the script which can Reorganize all indexes in each database and i have 75 servers and every server have 3 or 4 user databases and few read only databases...

    can any one help me in this!!

  • This should help you

    http://sqlfool.com/2011/06/index-defrag-script-v4-1/

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Why not use something thats already around ?

    Ive used the scripts from Ola Hallengren with great success in the past.

  • fawad.majid (6/3/2014)


    hi there

    i want to write the script which can Reorganize all indexes in each database and i have 75 servers and every server have 3 or 4 user databases and few read only databases...

    can any one help me in this!!

    Hello,

    If you really want to reorganize/rebuild all indexes that can be done quite easily with something like this:

    EXEC Sp_MsForEachTable @command1="SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REORGANIZE";

    If you're actually looking for a smarter solution that'll do rebuild or reorganize by fragmentation percentage etc, then I'll second the previously made suggestion to look at some of the existing solutions, I personally like Ola Hallengrens scripts.

    Mika Sutinen, Senior DBA
    @SQLFinn on Twitter
    Blogging at SQLStarters[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply