Home Forums SQL Server 2005 Backups Using INSERT INTO…SELECT to Bulk Load Data with Minimal Logging RE: Using INSERT INTO…SELECT to Bulk Load Data with Minimal Logging

  • Followup...

    I'm really reluctant to drop and recreate indexes. Let's say another dba or developer changes the index (add/remove columns to/from the index, change the FILLFACTOR, etc). My code would nullify those changes because I hard-coded the steps to create the index. Not good!

    A better option is to disable the index and rebuild it later. (Thanks to Andy Warren for his article about Disabling Indexes[/url]!)

    Here's my revised pseudo-code:

    TRUNCATE TABLE table_name

    ALTER INDEX nonclustered_index ON table_name DISABLE

    INSERT INTO table_name WITH(TABLOCK)

    (Column_Names)

    SELECT

    (Column_Names)

    FROM OPENROWSET (

    BULK 'data_file_path',

    FORMATFILE = 'format_file_path') alias

    WHERE condition

    ORDER BY column_with_nonclustered_index

    ALTER INDEX nonclustered_index ON table_name REBUILD

    If I get really motivated, I can programatically determine the non-clustered indexes and disable/rebuild them.

    Still, after reading the documentation on MSDN, I'm confused as to why any of this matters when the tables are truncated first...