Reindex a table

  • What is better

    truncate a table, reindex it and insert records

    or

    truncate a table, insert records and reindex it.

    😀

  • Option 2. Re-index after insert, so you don't fragment the index. Usually faster, too.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • thanks

    that's what i though but i want it to double ckeck

  • Definitely option 2 - since reindexing an empty table doesn't do anything. What I normally do is:

    1) Disable all non clustered indexes

    a) ALTER INDEX ncindex1 ON table DISABLE;

    2) Truncate the table

    3) Load the table with new data

    4) Rebuild all indexes

    a) ALTER INDEX ALL ON table REBUILD;

    You can't disable the clustered index, or the table is no longer accessible.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

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

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