SQLServer v2005, rebuild or re-organise index is not lowering fragmentation

Posted on 2008-11-08
Medium Priority
Last Modified: 2012-05-05

I've made up a new SQLServer db with about 95% of our production data as a test. I then dropped all the records and then filled the tables again with 100% of our data. The db seems fine.

I thought I'd look at the index frag because of the record drop and re-add and it was high in a few tables, >70%. I tried to do a rebuild and a re-organise but the frag level is same. These are primary keys, non-clustered.

I noticed the fragmentation is high only on the tables with not many records, < ~1000, and the frag on table with many records, > 50000, is fine, like about 0.2%. So are tables with not many records likely to have high frag?

I've tried rebuild and reorder in the SMSS (right click on index, rebuild) and also in code:
     ALTER INDEX ALL ON [dbo].[log_GRSPN]
        REBUILD WITH (
               PAD_INDEX  = OFF,
              ALLOW_ROW_LOCKS  = ON,
              ALLOW_PAGE_LOCKS  = ON,
              SORT_IN_TEMPDB = OFF,
              ONLINE = OFF )

Ideas ?
Question by:LukeB
  • 2
  • 2
LVL 17

Expert Comment

ID: 22914854
I reccomend you drop and recreate the indexes in question.

Author Comment

ID: 22914867
Hi Hogg

see SSIS help:


it specifically recommends against doing that ...
"You can also rebuild an index by first dropping the index with the DROP INDEX statement and re-creating it with a separate CREATE INDEX statement. Performing these operations as separate statements has several disadvantages, and we do not recommend this."
LVL 17

Accepted Solution

HoggZilla earned 2000 total points
ID: 22917341
I do realize it is not the first choice, but if the rebuild is not accomplishing your task? How about this, your options are limited to just a few.
Pros: Rebuilds index in one step which is good for clustered indexes, as it means that non-clustered indexes do not need to be rebuilt. Can be used to recreate (and thereby defragment) indexes created by constraints, if the index definition matches the requirements of the constraint.
Cons: Potential blocking problems with other processes in the same way as for drop and recreate index above

Author Comment

ID: 22917834
ok, I tried that, the frag level has gone from 80% to 55% ...
This table has a 2 field PK index, nonclusted, unique. The table has 5300 records. The 2 fields are HoleID (varchar(7)) and RunNumber(tinyint) which are unique when in combination. There are also many other fields in the table, non of which are indexed and do not need to be (v rarely searched on)
The code I used, per Hogg suggestion is :

     CREATE UNIQUE INDEX aa_tblGeophyx
     ON [dbo].[log_GRSPN]  (HoleID, RunNumber)
which got it down to 55%. So better but still high.
This is a parent table with a related table, log_GRSPN]_data , which has 26.9 mil records. Referential integrity is setup per SQLServer v2005, i.,e. not using triggers. This related table has 0.2% frag.


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Integration Management Part 2
Loops Section Overview

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question