Grigory P
Grigory P

Reputation: 191

MS SQL Server: how to optimize INSERT queries

Is there any way to optimize simple INSERT queries like the following?

INSERT master_table
    SELECT * FROM increment

The execution plan is Table Scan (13%) -> Table Insert (87%)

What can I do to make it execute faster?

Upvotes: 1

Views: 782

Answers (1)

Stu
Stu

Reputation: 32614

You leave little choice to scan the entire table as you want all the data, however a couple of things you can do.

  1. drop index, if you have any, on the master_table
  2. use insert into master_table with(tablock)...

This will make the inserts into the target table as fast as possible and untilise parallel execution for reading the table to do the insert, a feature that was added in 2016.

Upvotes: 1

Related Questions