troubleshooting Question

SQL copy rows from one database to another only if they don't exist in the target databse

Avatar of dbworker1
dbworker1 asked on
Microsoft SQL Server
8 Comments2 Solutions395 ViewsLast Modified:
To repair a database, rows need to be copied from one database to another but only if the row does not exist in the target database.

The tables have a primary key but this can't be used as the unique autoincrement ID may not correspond on the target database. We are using a datetime field that should be unique enough for the job. This is a one time operation so efficiency does not matter. MERGE cannot be used (older SQL server)

Table layout is identical and there are between 30 to 100K rows.

Database can be taken offline during the copy.

How can this best be accomplished?

Thank you
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros