Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hallo ALL,

How can i synchronize two databases sharing the same server. I have tables in each database. If my live database has some new entries in its tables. How can i compare with my other database table and add it to the other table. ?

For example, how can i have the data which is added new in table1 "C,D,E" inserted in Table 2


Thank you!

What I have tried:

Things i have tried:
SQL
INSERT INTO  [Database2].[dbo].[Table2]
SELECT * FROM [database1].[dbo].[Table1]


this query inserts all data in the table1 again, how can it be synchronized all time so that in case if there is any new data in Table1 it updates into table2

Table 1 : LIVE DATA
| Field1 | Field2 | Field3 |
 | ------ | ------ | -----: |
 |  A     |   1    |  10   |
 |  B     |   2    |  20   |
 |  C     |   3    |  30   |
 |  D     |   4    |  40   |
 |  E     |   5    |  50   |


Table 2 :
| Field1 | Field2 | Field3 |
 | ------ | ------ | -----: |
 |  A     |   1    |   10   |
 |  B     |   2    |   20   |
Posted
Updated 18-Jan-18 23:37pm
v2

Seems, you're talking about Database Mirroring (SQL Server) | Microsoft Docs[^], which is the best option to you.
If your non-live database is on the same server, you may want to create a stored procedure[^] which inserts data into live database, then into the mirroring database.
 
Share this answer
 
If you have distinct value in Field1 field you can try this

INSERT INTO [Database2].[dbo].[Table2]

SELECT * FROM [database1].[dbo].[Table1] with(nolock)
where Field1 not in (select Field1 FROM [Database2].[dbo].[Table2] with(nolock) )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900