I’d like to know the theoretical time. I know that every server will vary some.
I am pulling 1,000,000 99Byte rows from a SQL2K Database into a SQL2005 DB on the same server instance.
There are indexes on the source table. execution plan indicates <missing index>????
There are no indexes on the destination table.
The query is taking about 1 minute. That seems really really long….considering it’s a simple insert into
INSERT INTO EDW.STAGE.DESTINATION
SELECT AccountNumber, CardNumber, FiscalYear, SeqNumber,Category,DateSaved, FullLandValue, FullBuildingValue, TotalValue, ValueExemption,TaxableTotal,DataPreAssesGeneralID,getdate(),2010 FROM SOURCE WHERE FiscalYear = 2010
I bet there is a way to speed this up…but how?
Update
This is actually a dynamic SQL statement. for brevity I only am showing the generated string. I tested the statement as a dynamic vs t- SQL and the execution times were identical.
You mention indexes on the destination table, but not the source. If the source table doesn’t have a non-clustered index on the FiscalYear column, add one. That should speed up the inner query (the
SELECT).Additionally, you could include the other columns you are selecting on the index to eliminate a key lookup from the execution plan. (If the columns in the
SELECTstatement represent all the columns in the table, then perhaps a clustered index on the FiscalYear column would be better, but this may interfere with an existing primary key, if there is one.)Or you could always beef up the hardware on the box, but that might be overkill for optimizing an
INSERTstatement.Edit:
You could also use SSIS to move the data. You can save the SSIS package and either call it from an application or schedule it on the SQL Server.