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

Posted on 2008-11-08
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
    LVL 17

    Expert Comment

    I reccomend you drop and recreate the indexes in question.
    LVL 1

    Author Comment

    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

    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
    LVL 1

    Author Comment

    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

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now