views:

500

answers:

2

My query is related to the answers i got for questions i had posted earlier in the same forum. I have a copy of a client database which is attached to SQL Server where the Central Database exists. The copy already contains the updated data. I just want to transfer the updates from that copy to Central Database both holding same schema and are present in the same server using C# .NET. One of the solution i got was to create SSIS package and run it from the UI. I want to know as how i can create SSIS Package to achieve this. I am new to SSIS. I am using SQL Server 2005 Standard Edition and Visual Studio 2008 SP1 installed. I learnt that BIDS 2005 is used to create packages which comes by default with SQL Server 2005. Can someone please give me a example as i am new to this.

A: 

If you are merely updating data in a table from data in another table, I would say SSIS is overkill for this. I would create a proc that your .NET package can call which would simplify the process and ease the learning curve.

rfonn
Thanks for the reply. The copy of the client database may consist of new insertions of data also along with the updates for many tables not just one table. i want the changes to be reflected in the central database. I am not concerned about deletion as i am only interested in transferring the updates and any new insertions already present in the copy of client database to central database. There are atleast 50 tables and maybe equal number of views and stored procedures.
Pavan Kumar
+1  A: 

There is no easy way to do this in SSIS that I know of. For each table, you would have to write a proc which can be called in SSIS using the Execute SQL Taske. For example:

src table
SSN First_Name Last_Name
11111111 Jeff Williams
22222222 Sara Jenkins
33333333 George Anderson

dest Table
SSN First_Name Last_Name
11111111 Jeff Williams
22222222 Sara Flowers
55555555 Jessica Billows

Proc:

INSERT INTO dest(SSN, First_name, Last_Name)
SELECT s.SSN, s.first_name, s.last_name FROM @src s LEFT JOIN @dest d ON d.SSN = s.SSN WHERE d.SSN IS NULL

UPDATE dest
SET dest.First_Name = src.First_Name, dest.Last_Name = src.Last_Name
FROM dest JOIN src ON src.SSN = dest.SSN

Producing this type of logic could prove to be a little tedious. You could use a handy tool like red gates sql compare to accomplish this a lot quicker: http://www.red-gate.com/products/SQL_Data_Compare/index.htm

Good Luck!

rfonn
Thanks a ton...:)I am very new to SSIS also. It may be a daunting task for me to repeat the procedures for all the tables but i think i can only see this as a solution for now. Red-gate will be an expensive solution for me as i cant afford it. Can i be in contact with you?. Can you pass me your email-id so that i can atleast mail you if i have any queries. Thanks again!:)
Pavan Kumar
For some reason the INSERT statement didnt work for me. I am assuming that you have tried to insert from one table to another within same database. I tried it and i got some error. Can you please check it once ?
Pavan Kumar
i just modified your query and I think this query should work for me..:) INSERT INTO dest(SSN, FName, LName) Select source.SSN, source.FName, source.LName FROM source LEFT JOIN dest ON source.SSN = dest.SSN AND dest.SSN IS NULL WHERE source.SSN NOT IN (select dest.SSN from dest)
Pavan Kumar
Pavan-I just changed the query above and actually tested it out this time, =). It's similar to what you did above-may want to test both approaches with larger datasets to improve perfomance. Glad I could help!
rfonn
Thanks bro...:) I actually was trying to understand ADO.Net and SSIS. It didnt really help me out much. I didnt even know if they can be the solution for my problem. These queries should help me solve the major part of the problem...:)
Pavan Kumar