SQLTeam.com | Weblogs | Forums

I want to marge some data in same database

sql2008r2

#1

Dear Team,

Please help and guide me, I want to marge some data in same database.

Example: I have two databases server, also two databases are same, and actually (database, servers [SQL server r2], database name as [inteacc, inteacc], table, view, SP, function) everything is same,

DB-1: one is live (Production server) they have one year [2018] data, and, transaction is occurring regularly, in the mean time I have taken a full backup, and restore in [DB-2], after that, I have deleted data from the DB-1 for the first three (3 as Jan1 to March31) month, now live server have 9 month plus current production data, is equal 9 month plus (+), but [DB-2] have only one year data, now I want to take back from [DB-1] and want to include with [DB-2], which is not in [DB-2]. I think SQLTeam experts are understanding my requirement, I hope they will help me recently, waiting to positive feedback.

Thank-you Everyone
Fokrul Islam
Head of IT at HATIM Group


#2

If you are unsure about the following procedure, I whould recommend you create a development environment, where you restore a fresh backup from production server, and then you can test on this, instead of potentially damaging production data.

First, take a fresh backup in case something goes wrong!

In order to have the least amount of stress on your production server, I would do the following:

On server2:

  • create new database
  • insert data into db1 on new database where you only select from jan 1st to march 31st
  • verify that you have all you missing data in new database (not more, not less)
  • backup your new database

On Server1:

  • restore your backup into new database
  • verify that you have all you missing data in new database (not more, not less)
  • insert data into db1 from new database
  • verify that you have all you missing data in original database

If all is ok, delete new database on server1 and server2


#3

Dear expertise, Many many thank to you for reply me, thank you so much. ,

please see my attached picture, i hope you could understand what is my requirement?


#4

You have the db1 database restored to the db2 server so now just need to merge the data locally on the db2 server.
This means looking at the tables and writing queries to merge the data.

That may be simple if you just need to insert new data and there's something that sequences the rows and the source database just does inserts but more likely you have updates and will need to run merge statements.
If you need to do this sort of thing it's useful to have inserted and updated time columns on each table.