I am trying to transfer data from one db to a new one. i am fetching data from one table say i fetch name of person, then i insert this into say Table Person. this will generate a personID which i want to insert into say Address Table. What should be the approach using SSIS. Any suggestions?
相关问题
- SQL Server Import Wizard doesn't support impor
- Bulk insert from excel to sql for selective fields
- What other dependencies do I need to install in Vi
- Deployed SSIS Package not reflecting changes made
- Building SSIS solution using visual studio online
相关文章
- SSIS solution on GIT?
- How can I manually fail a package in Integration S
- See complete tooltip error message for Data Flow S
- Save content of Email body in outlook to a file
- What is Big Data & What classifies as Big data? [c
- What is the actual use of buffer temp and blob tem
- Object Variable in script tasks
- SSIS Script Task Not Running Excel Macro With AddI
You have a couple of ways to go here.
So if you decide to go for #2, here is how you would do it.
Create Two Tables to represent your Old Sytem and New System:
Fill The person Table with two entries:
alt text http://www.freeimagehosting.net/uploads/ff56e32bea.gif
Create a stored procedure to do the inserts and return the new id:
Next, we'll set up the SSIS package. In this sample package, add a single Data Flow task. In the data Flow Task add the following tasks and wire them up as shown.
alt text http://www.freeimagehosting.net/uploads/5348332a9e.gif
Note the data viewers are there to show you the results as we progress.
Set up the OLE DB Source Task to pull all of the columns from the Person_OldSystem table.
Set up the Derived Column Task to add a column called 'NewID'
alt text http://www.freeimagehosting.net/uploads/a5c6c9e7c6.gif
Set up the OLE DB Command Task with the following SQL.
In the OLE DB Command Task's Advanced Properties, set up the following column mappings:
alt text http://www.freeimagehosting.net/uploads/2224622431.gif
So what we've done with the data flow is to extract the list of people from the old system. We then add a new column, called NewID, to hold the identity of the row when it is inserted into the new table.
alt text http://www.freeimagehosting.net/uploads/8162127377.gif
The OLE DB Command calls our stored procedure which does the insert and reutrn the id of the new row in the last parameter. This returned id is then mapped into the column in the data flow we preared for it.
alt text http://www.freeimagehosting.net/uploads/97dbfba277.gif
The conditional split is there to give the data flow somewhere to go.
It all depends on your specific situation. Here are a couple of possibilities:
Do you have the business key (for instance the name of the person - anything that uniquely identifies a Person record) of the person available when loading the Address table? If yes, use that to perform a lookup on the Person table.
Or are you more looking for a way to create new Address records for the newly-created Persons? In that case, the ideal situation would be that you have a Created datetime field in your Person table which would get filled at the moment that the Persons are inserted. You can then use that timestamp to retrieve all Person IDs, for instance all Person records with Created > the largest Created timestamp of the Address table.
Again, it all depends so the above may need some adaptation to your specific situation. I do hope it gets you started though.
I would suggest having two separate dataflows-first one loads your person table from your ? source table and the second one loads your address table with the person id.
Create another control flow task and in the data flow section, fetch the personid from the source table which you said as Person table and insert into the destination table which is the Address table