Output PRINT cmd

  • I am tryingto automate re indexing based on the fragmentation.

    some thing like this.

    IF @frag < 30.0

    SET @command = N'ALTER INDEX ' + @indexname + N' ON ' +

    @schemaname + N'.' + @objectname + N' REORGANIZE';

    IF @frag >= 30.0

    SET @command = N'ALTER INDEX ' + @indexname + N' ON ' +

    EXEC (@command);

    PRINT N'Executed: ' + @command;

    I would like to get an out put message so that i can know which indexes are rebuild, either in a email or a text file. How can i do it?

  • I've used this http://www.sqlservercentral.com/scripts/Index+Management/30721/ before to log reindexing, I think it works on SQL 2005 as well you'd need to try it.

    Facts are stubborn things, but statistics are more pliable - Mark Twain
    Carolyn
    SQLServerSpecialists[/url]

  • Mike Levan (12/2/2008)


    I am tryingto automate re indexing based on the fragmentation.

    some thing like this.

    IF @frag < 30.0

    SET @command = N'ALTER INDEX ' + @indexname + N' ON ' +

    @schemaname + N'.' + @objectname + N' REORGANIZE';

    IF @frag >= 30.0

    SET @command = N'ALTER INDEX ' + @indexname + N' ON ' +

    EXEC (@command);

    PRINT N'Executed: ' + @command;

    I would like to get an out put message so that i can know which indexes are rebuild, either in a email or a text file. How can i do it?

    A number of ways are possible. One really simple one that comes to mind is to build a temporary table, insert the indexes you update into it and then select from that at the end of your process.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • This SSC article does ONLINE/OFFLINE re-index, and sends report in Email

    http://www.sqlservercentral.com/scripts/SQL+Server+2005/61278/

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005

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

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