Rebuild index after truncating the rows...

  • I have a database with 10 tables. And each table has a index (there are clustered indices for three tables and non-clustered on the other tables). Every week I truncate all the data from these tables and load new data.

    In this case, can I rebuild the indices using ALTER INDEX with REBUILD like:

    ALTER INDEX ALL ON Table1

    REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON,

    STATISTICS_NORECOMPUTE = ON);

    Or do I need to drop the indices before truncating the tables, than truncate the data and create the indices on the tables again.

    Also, what does STATISTICS_NORECOMPUTE do, i am still confused after going through BOL.

    Thanks.

  • Your load will go a little faster if you can drop the non-clustered indexes before the truncate, and add them back in after the new data is loaded in.

    You may also want to test whether it's faster to also drop the clustered index as well (which I would do AFTER the truncate if you want to try). That's more of a toss up (sometimes faster one way, sometimes not).

    If you do decided to drop the clustered index, then be sure to rebuild it before the non-clustered.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

Viewing 2 posts - 1 through 1 (of 1 total)

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