SQL Server INSERT into huge table is slow

OK, here’s what I would do:

  1. Check to see if you need both indexes [IX_ACCOUNT_ID_POINTS_CODE] and [IX_ACCOUNT_ID] as they may be redundant.

  2. Before you do the INSERT, Disable the Trigger and drop the Foreign Keys.

  3. Do the INSERT setting the fields normally set by the Trigger, and insuring that the FK Column’s values are valid.

  4. Re-Enable the trigger, and re-create the Foreign Keys WITH NOCHECK.

I would leave the indexes on as you are inserting less than 0.2% of the total row count so it’s probably faster to update them in-place rather than to drop and rebuild them.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)