Merge two SQL Server databases

1129100 pts.
Tags:
SQL Server
SQL Server database
I have two SQL Server databases and they have the same schema. But both may have issues with the primary key in some tables (so I want to get rid of the duplicate rows). How can I merge these two databases? Appreciate any help available.
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    What are you planning on if the tables have different row counts? Are you looking to add missing rows to table 2 that exist in table 1? Then run this, flipped so rows that existed in table 2 but not in table 1 are added to table 1?
    128,275 pointsBadges:
    report
  • edwinjhoffer
    you need to check the PK values and then exclude them from you SELECT statement, like : 
    INSERT INTO destDB.dbo.Table
        (...)
    SELECT *
    FROM sourceDB.dbo.Table
    WHERE NOT PK IN
        (SELECT PK
         FROM destDB.dbo.Table)
    
    3,740 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: