Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My problem is how do I maintain an index on table, weekly we are deleting and inserting bulk amount of data from the table.Because drop and create index taking too long time..

share|improve this question

You could set up a job to rebuild or reorganize them weekly/daily.

I recommend checking out

This index rebuilder is highly customizable.

share|improve this answer

What you want to do is have an ongoing analysis of the fragmentation of the indexes pertaining to your particular table. The below query will show you average fragmentation per index for all indexes in your particular object that have a record_count of 1000 or greater:

        when ps.avg_fragmentation_in_percent < 5
            then 'NO ACTION'
        when ps.avg_fragmentation_in_percent >= 5
            and ps.avg_fragmentation_in_percent < 30
            then 'REORGANIZE'
        when ps.avg_fragmentation_in_percent >= 30
            then 'REBUILD'
    end as recommended_action
from sys.dm_db_index_physical_stats
) ps
inner join sys.indexes i
on ps.object_id = i.object_id
and ps.index_id = i.index_id
where ps.record_count >= 1000

You can work this into a logical script that is run on a schedule depending on your environment and how big of a maintenance window you have. A good rule of thumb is that fragmentation of 5% to 30% warrants an index reorganization, and 30% or greater should be rebuilt.

Edit: I've worked in simple CASE logic to help with the rule of thumb calculation.

share|improve this answer

Also check out Ola Hallengren's excellent database maintanence script at

You can customize it to ignore backups & integrity checks if you dont need them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.