Friday, March 23, 2012

Merge 2 Databases?

My problem is this:

I have a database file on a hard disk. I have to read that data and merge it into a database on a sql server. How can you merge ? The databases are set up the exact same way. The only difference in them is the data.

Also, in the database file I have image names, I have to compare them to what is on the database on the sql server.

Thanks

There are many options.
bcp out and in|||

Not very much data at all. Maybe 500 rows with 10 columns.

I am worried about using DTS because what happens with the foreign keys and primary keys?

Say I have imageID as a primary...and I have imageID 1, 2, 3 in both databases....won't there be conflicts when I run the DTS?

|||

In that case I would go for the good old T-SQL syntax.

You can work cross database.

INSERT INTO myTable (myField, myOtherField)
SELECT myField, myOtherField FROM myOtherDatabase.dbo.myTable

|||

Thanks Wesley for that...

But lets say I have imageID 1, 2, 3 in DB1 and I have imageID 1,2,3 in DB2. Now the images associated to those ID's are totally different. How can I insert the data from DB2 into DB1 without getting errors? I have to somehow increment the ID's in DB2 so they are 3, 4, 5?

|||Takes some logic, you could use a cursor since it's a small recordset and insert the records one by one using SCOPE_IDENTITY to determine the current ID for the child records.

No comments:

Post a Comment