How to Insert and Delete the rows in the same Table

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
prmuttireddy
Participant
Posts: 30
Joined: Tue Jun 20, 2006 10:22 pm

How to Insert and Delete the rows in the same Table

Post by prmuttireddy »

Hi,

How to Insert and Delete the rows in the same Table within a single job.
Please clarify the issue.

For example let assume SRC as source table and TRG as Target Table. I want to Insert and Delete in the TRG table according the SRC table changes.

Advanced Thanks,

Reddy.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

This is a typical DataStage task and often done. You can use the same stage canvas object for the insert and the delete by having two links into it, or you can use two separate stages. The logic of which row gets sent down which link is done with constraints in a transform stage.
What logic have you tried so far that hasn't worked, if you explain that we might be able to give targeted assistance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The writing rule "replace existing rows completely" effects DELETE followed by INSERT for each row sent to the target.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
prmuttireddy
Participant
Posts: 30
Joined: Tue Jun 20, 2006 10:22 pm

Post by prmuttireddy »

Hi,

Thanks for immediate reply.
The scenario is

In the constraints part of the Transform stage I mentined as
If A_ACT='A' or 'U' then it should be Insert in the Target
and If A_ACT='D' or 'B' it should be Delete in the Target

Means if source side record Inserts or update it should be insert and if source side records deletes it should be delete in the target.

Regards,
Reddy.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Supply only the key column(s) on the link that looks after DELETE operations. Use user-defined SQL of the form

Code: Select all

DELETE FROM tablename WHERE keycol = '?';
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
prmuttireddy
Participant
Posts: 30
Joined: Tue Jun 20, 2006 10:22 pm

Post by prmuttireddy »

Hi Ray,

when i am trying to use two DB2 stages as Target, one for delete and for Insert it has been giving the Deadlock error.

Reddy.
ascen
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 12, 2006 6:47 am
Contact:

Post by ascen »

prmuttireddy wrote:
when i am trying to use two DB2 stages as Target, one for delete and for Insert it has been giving the Deadlock error.
Use only one target db2 stage with to input links. And do not use any options like: "Truncate table before insert" on two iput links.

Best regards,
Piotrek
prmuttireddy
Participant
Posts: 30
Joined: Tue Jun 20, 2006 10:22 pm

Post by prmuttireddy »

Could you please tell what option i have to select in the target DB2 stage.

Regards,
Reddy.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No specific options. The 'fix' is to simply use one target stage instead of two so they are aware of each other and run in the same transaction - this will resolve your deadlock issue.

As long as your constraints and update actions are fine, having both links run into a single stage should be the only change you need to make.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply