how to update or insert
Moderators: chulett, rschirm, roy
how to update or insert
i am using db2 table as source and populating to target. my requirement is if the records are allready exists in the target they should be updated or inserted. target table has 20 columns but i need to update only 5 columns, but i am not populating the primary key into the tartet table in this job. its urgent pls give answer asap.[/b]
Thiru,
please be aware that normally post with "urgent" and "asap" are handled with lower priority in this forum. If you have a service provider you can go to them and expect quick turnaround, but DSXchange is a community of volunteers.
The question you have asked has been posed before and is also one of the base functionalities of working with DataStage; so fortunately while you wait for an ASAP answer in this forum you could use the search facility or look at your training material or product documentation.
please be aware that normally post with "urgent" and "asap" are handled with lower priority in this forum. If you have a service provider you can go to them and expect quick turnaround, but DSXchange is a community of volunteers.
The question you have asked has been posed before and is also one of the base functionalities of working with DataStage; so fortunately while you wait for an ASAP answer in this forum you could use the search facility or look at your training material or product documentation.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Hi Thiru,
In you DB2 stage, set the Write method to UPSERT.
But be aware... even if the Datastage's documentation says that it does an Update first, and if the row is not found, an Insert... it does not really works this way...
It first does an Insert, and if it fails (due to a unique constraint or a primary key), then it will update the row....
The problem with that is, if you do not have a unique constraint or a primary key... for any reasons... it will always insert records in your table...
In that case, you will not have the choice... use a lookup stage (or a Change Capture stage... depends of your case), and use a switch stage to redirect the data to an Update or an Insert DB2 stage.
Hope this will help.
Thanks
In you DB2 stage, set the Write method to UPSERT.
But be aware... even if the Datastage's documentation says that it does an Update first, and if the row is not found, an Insert... it does not really works this way...
It first does an Insert, and if it fails (due to a unique constraint or a primary key), then it will update the row....
The problem with that is, if you do not have a unique constraint or a primary key... for any reasons... it will always insert records in your table...
In that case, you will not have the choice... use a lookup stage (or a Change Capture stage... depends of your case), and use a switch stage to redirect the data to an Update or an Insert DB2 stage.
Hope this will help.
Thanks
The Brute
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Of course, any of these "dual-mode upserts" have a performance overhead, as each involves up to two operations (replace is delete then insert). It's much better to perform existence checking within the job design then have a stream for "insert only" and a stream for "update only".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.