Q
Problem solve Get help with specific problems with your technologies, process and projects.

Migrating data into SQL Server in one query

I am attempting to migrate data from a flat file database to SQL Server. I would like to maximize speed by minimizing queries. There is already data in the SQL Server target table, so I don't want an error when trying to insert data that has the same index. I can see how to do it with two queries. The first is to check for the index already existing and then using a NOT IF statement on the recordcount to then do an insert. Is there a faster way, such as in a single query to check for existing data and do the insert only if it doesn't currently exist? The other way is to trap the error of the PK being a dupe.

You can't do this with a single query. Sometimes brute force is the best method. That's what I ALWAYS use when importing data into existing. Getting fancy usually winds up in causing errors that you can't easily back out of. Dump the data into a staging table. Scrub the data. Log any exceptions and move them to an exceptions table. Load the scrubbed data into your production table.

 

For More Information

This was last published in April 2003

Dig Deeper on Microsoft SQL Server Installation

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close