SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Indexing During an INSERT INTO Statement


Indexing During an INSERT INTO Statement

Author
Message
rd-600137
rd-600137
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 61
I have a script that appends (INSERT INTO) records from a staging table to a production table that has many indexes on it. At the end of the script I refresh all the indexes automatically for that table (using DBCC DBREINDEX(tblName,'').

Is there a way to have the indexes update automatically during the INSERT INTO statement, so that I don't have to run the DBREINDEX statement?

I realize this might not be optimal from a performance standpoint, but would like to test it anyway, do some comparisons, etc.

Is there a setting that lets me do this?
Gethyn Ellis
Gethyn Ellis
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2687 Visits: 2905
I have a script that appends (INSERT INTO) records from a staging table to a production table that has many indexes on it. At the end of the script I refresh all the indexes automatically for that table (using DBCC DBREINDEX(tblName,'').

Is there a way to have the indexes update automatically during the INSERT INTO statement, so that I don't have to run the DBREINDEX statement?

I realize this might not be optimal from a performance standpoint, but would like to test it anyway, do some comparisons, etc.

Is there a setting that lets me do this?


RD - in answer to your question the indexes will automtically 'be updated' when the insert happens, that is the new data will be included in all the indexes on that table.

Without going into detail on how indexes work many new inserts on a given table can cause the indexes to become fragmented and then not used in future query plans as a table scan is deemed more efficient. rebuiling the indexes at the end of insert script ensures that fragmentation is minimised and the index remains useful...Hope this helps

Gethyn Ellisgethynellis.com
rd-600137
rd-600137
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 61
Very helpful, thanks Ellis.
Joseph-465703
Joseph-465703
Mr or Mrs. 500
Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)Mr or Mrs. 500 (566 reputation)

Group: General Forum Members
Points: 566 Visits: 465
DBCC INDEXDEFRAG is command to defrag an index.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search