all groups > sql server dts > july 2003 >
You're in the

sql server dts

group:

Auto update insert delete bet. 2 tables


Auto update insert delete bet. 2 tables Flo
7/14/2003 2:30:55 PM
sql server dts:
I am trying to develop an automatic synchronization between 2 tables and run
it once a day.

The fields of the Source Table are : SSN, first, last, phone, email
The fields of the Destination Table are : IT_ID, SSN, first, last, phone,
email (the same 5 fields + a unique ID)

During this synchronization, I would like to:
a.. delete records in my destination table if they have been deleted in my
source table
b.. insert records in my destination table if they have been inserted in
my source table
c.. update records in my destination table if records are in the source
table
I heard that the best way to do it is using Data Driven Task, but I don't
know how to use them for my matter...

Any help is welcome,
Thank you,
Flo

Re: Auto update insert delete bet. 2 tables Flo
7/14/2003 6:20:18 PM
I forgot to mention that I have about 2000 records so I think I could DTS
over the whole lot and not having a trigger on the source.
My problem is that I don't know how? I am using DTS designer and I don't
know if I have to use a special query on the source? I didn't specify any.
I specified the following transformation:

Function Main()

Select Case Trim(DTSSource("employee"))
Case "New"
Main = DTSTransformStat_InsertQuery
Case "Change"
Main = DTSTransformStat_UpdateQuery
Case "Delete"
Main = DTSTransformStat_DeleteQuery
Case Else
Main = DTSTransformStat_SkipRow
End Select

End Function

And then for the insert I specified something like that:
INSERT
INTO dest_table
(SSN, FIRST_NAME, LAST_NAME, WORK_PHONE)
VALUES (?, ?, ?, ?)

But the parameters are values of the destination table instead of of the
source table.

Thank you,
Flo


[quoted text, click to view]

Re: Auto update insert delete bet. 2 tables Allan Mitchell
7/14/2003 11:28:03 PM
OK What you would do is this

Have a trigger on the Source. it logs to a table the INSERT/UPDATE/DELETE.
You would generally have a field in there as well as a flag with values of
U,I,D for obvious reasons. You would then use this to determine through the
Data Driven Query Task what to do with the data.



If there are not too many records in the source it may be quicker to DTS
over the whole lot
Then use TSQL to do it

Key in Source not in Dest = INSERT
Key in DEST not in Source = DELETE
Key in both = UPDATE

--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



[quoted text, click to view]

AddThis Social Bookmark Button