Sql-server – Keeping database in synch

data synchronizationmigrationsql server

This might seem like a stupid question.
Can i restore logs of one database to another existing database of same schema.?

I have a database d1 in Server A.I took backup of that and restored as database d1 in another database server B
Then in server B i merged all data from database d1 to database d2.
But i still want to apply transnational logs from database d1(in Server A) to database d2.Is that possible?

This might seem a generic/broad question?But it is a valid question as i have similar scenario of migrating legacy data and current production data into a new sql server after merging current production into legacy, and stay in synch with current production.

I thought of log shipping and tried as well.The issue was server A is in lower version(2008 R2) and server B in higher version(2016).So i have to run log shipping in no recovery mode and i can't do merging on the data in secondary in no recovery mode.If i stop log shipping and bring the database to recover mode and do merge ,i can't put it back to non recovery mode again and enable log shipping.

Please note i merge database d1 to d2 in server B.

Best Answer

No. In order for a log to be restored to a database, the log sequence number (LSN) of the log has to be the correct number to match what the database requires for the next log to be restored. If you could somehow get the LSNs to match, restoring a log from a different database would corrupt it as some operations contain page IDs, and the page IDs are not going to be the same on both databases.

There are probably quite a lot of other reasons why this won't work, but it really isn't necessary to document all the reasons why as it is something that is simply not designed or expected to be able to work that way.