Home Forums SQL Server 2005 T-SQL (SS2K5) Primary Key creation - before and after bulk insert RE: Primary Key creation - before and after bulk insert

  • One additional thing to consider is what is the order of your data? If the order of the data you are inserting very closly matches the clustered index then you will get much better performance than if it doesn't.

    I wrote a piece of code a number of years back to upgrade between 2 versions of a piece of software. In the end for speed purposes we had to drop and save all of the indexes then re-create them at the end. This was not always the fastest way to move the data though so we had to put in a flag, drop indexes or not. The determining factor was of course size of the table. And unfortunatly it wasn't an exact number of rows, and we ended up using testing and experience to decide which way to go.

    I think however that in your case (aprox half a mil) you are safe enough creating the index at the end. However, again you will get alot of bang for your buck if you insert the data in the order of the clustered index. Even realizing the cost of doing an ORDER BY on your query.

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]