June 27, 2008 03:27 PM

Rebuild Only the Indexes that Need Help

Avoid the performance impact of rebuilding willy-nilly
Rating: (0)
SQL Server Magazine
InstantDoc ID #99019
Executive Summary: Don’t give in to the temptation of rebuilding your indexes at the first evidence of fragmentation. Instead, use the rebuild_indexes_by_db stored procedure to tackle only the indexes that actually need help.
...

You must be a paid Professional Member to access this entire article.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Monthly or Annual

Professional Membership

VIP Membership

Compare Member Benefits

Add a Comment

I had to add [] around index names in the genereated ALTER INDEX and UPDATE STATISTICS to get around indexes with white spaces in the name:

SET @Rebuild = N'ALTER INDEX [' + @IndexName + N'] ON ' + @FullName + N' REORGANIZE' ;

Torge3/24/2009 10:10:20 AM


I had to add [] around index names in the genereated ALTER INDEX and UPDATE STATISTICS to get around indexes with white spaces in the name:

SET @Rebuild = N'ALTER INDEX [' + @IndexName + N'] ON ' + @FullName + N' REORGANIZE' ;

Torge3/24/2009 10:10:20 AM


The same subject again... rebuild the indexes and stuff... I know that a lot has been said about performance, I believe that everything about that has already been told, at least regarding SQL Server 2000 and 2005 under Windows 2000 and 2003. Maybe it is time to find new subjects to write about...

Marcos2/13/2009 7:00:46 AM


It appears that you may need to uncomment out the EXEC in the sp to actually rebuild the indexes. Right now it is only printing out the commands and not actually executing them for testing purposes. So find the lines similar to the ones listed below and change the commented out statements to run the ALTER INDEX commands.

-- Catch any individual errors so we can rebuild the others
BEGIN TRY
-- EXEC(@Rebuild);
PRINT @Rebuild ;

Andrew8/27/2008 7:20:00 PM


to rpanigas: please see if your database has compatlevel set to 90 :-). According to my findigs, this is the problem.

Calin7/18/2008 8:20:30 AM


Where is the rest of the code for this? The download only has the procedure name and the parameters, as shown in the article, not the code as advertised. This code is great I am sure, and I really want to check it out.

Mindy7/7/2008 12:25:24 PM


Hello,
Great article! I fully agree with your findings. It seems that the provided stored proc produces an error when executing (creation of the sp). Is there an updated version? I've executed this code on a SQL 2005 server.
Below is the error

Msg 102, Level 15, State 1, Procedure rebuild_indexes_by_db, Line 14
Incorrect syntax near '.

Looks like the last line is having the problem.

Thanks

Rudy7/4/2008 7:53:18 AM


DHAY1999, thanks for notifying us of the problem. The procedure in Listing 1 does indeed appear incomplete. I will contact the editor and get the problem resolved ASAP.

Anne7/1/2008 8:57:15 PM


Good article, but where is the rest of the procedure?

david7/1/2008 2:37:15 PM


You must log on before posting a comment.

Are you a new visitor? Register Here

Related Resources

SQL Server 2008 Memory and CPU Highlights
A Tip Guide by Intel, Microsoft, Unisys
Special Report: Perspectives on SQL Server Sprawl
A Essential Guide by PolyServe
More

Field data type change - query timeout

Hi,       I need to change a data type of a field in SQL Server 2005. The fiels most be changed from varchar(13) to varchar (20), but because of th...222-96220

GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS