Reputation: 49
Upvotes: 1
Views: 566
Reputation: 43626
You need to be able to read/load the data from the local database to your server database.
This can be done via Linked Servers - if the servers are linked you can query data from the db2
from the context of db1
.
It will looks like:
SELECT *
FROM [server].[db2].[schema].[table];
If this is not possible I am guessing you have another way to move the data there (via BCP command or maybe just script the table and the data using SSMS from db2
and create it in db1
(4000 rows is not much and you should be OK to just copy the generated SQL).
Now, having the data in one place, you must have a way to identify which rows to insert.
This can be done easily like this:
SELECT *
FROM db2Table
EXCEPT
SELECT *
FROM db1Table
So, if there is row in the db2Table
that is not found in the db1Table
it will be returned. Then, just insert these rows.
Please, note that EXCEPT
with *
is comparing all columns. So, if you have a column like ID INT IDENTITY(1,1)
you will need to exclude it from the SELECT
list.
Also, if you have a way to map the data between the two tables by ID
or GUID
(a lot of folks are using UNIQUEIDENTIFIER to synch data), you make perform more complex operations. For example:
GUID
record is missing in the db1
table - insert itGUID
record is found in the db1
table - update itUpvotes: 1