Re: Mirror one table from 1 db to another
- From: "Stephen Howe" <sjhoweATdialDOTpipexDOTcom>
- Date: Tue, 20 Jun 2006 02:09:22 +0100
I need to be able to merge data regularly from a certain table on DB B to
the corresponding table in DB A.
How so?
Is table on DB A supposed to be identical to the table on DB B?
I suspect the answer is no.
The way I would do this is 2 steps
(i) make DB A aware of DB B. You can do this by adding a linked server. All
databases support this AFAIK.
(ii) Having done this, issue some SQL to merge regularly. I suspect you want
do SQL INSERTs and possibly SQL UPDATEs but not SQL DELETEs
So
INSERT INTO table1 SELECT * from linkeddb.dbo.table1 lt1 LEFT JOIN table1 t1
ON lt1.field1=t1.field1
WHERE t1.field1 IS NULL
should do it. Your inserting rows present on DB B that are not present on DB
A.
The ON clause should contain a full list of PK fields.
A Connection Execute should do it, no need to bother with Recordsets.
The UPDATE is similar if you wish to update non PK-fields on DB A which are
now different on DB B.
UPDATE table1 SET nonpkfield1=lt1.nonpkfield1, nonpkfield2=lt1.nonpkfield2
FROM linkeddb.dbo.table1 lt1 JOIN table1 t1 ON lt1.field1=t1.field1
WHERE t1.nonpkfield1<>lt1.nonpkfield1 OR t1.nonpkfield2<>lt1.nonpkfield2
The WHERE clause filters out all the rows where all nonPKfields are
identical.
All of this should be a lot faster as you are making the Jet Engine work for
you.
Stephen Howe
.
- Follow-Ups:
- Re: Mirror one table from 1 db to another
- From: Andy DF
- Re: Mirror one table from 1 db to another
- References:
- Mirror one table from 1 db to another
- From: Andy DF
- Mirror one table from 1 db to another
- Prev by Date: Re: Here's a rather broad question...
- Next by Date: Re: Mirror one table from 1 db to another
- Previous by thread: Mirror one table from 1 db to another
- Next by thread: Re: Mirror one table from 1 db to another
- Index(es):
Relevant Pages
|