Delete DB2 Table Rows

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
Mikey
Participant
Posts: 32
Joined: Fri Jan 15, 2010 3:21 pm

Delete DB2 Table Rows

Post by Mikey »

I'd like to delete all the rows from a DB2 table using an ODBC Stage before doing a mass insert. How can this be done if there's no input/output from a stage? Also, the table has 500,000+ rows so I'd like to turn logging off. I read another post that mentioned using a command similiar to "ALTER TABLE TableName ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" rather than using "Delete * from TableName". Again, there's no input or output; is there a way to do this easily?
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Row generator --> Transformer --> ODBC
In the row generator set Number of records to one.
You are the creator of your destiny - Swami Vivekananda
Mikey
Participant
Posts: 32
Joined: Fri Jan 15, 2010 3:21 pm

Post by Mikey »

I don't see "row generator" in the palette...where is that?
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

I didn't read your post properly. Row generator is available only in parallel job.

Transformer --> ODBC
Define a dummy stage variable in transformer and add a constraint @OUTROWNUM < 2

In ODBC write a user defined sql to delete the table.
You are the creator of your destiny - Swami Vivekananda
swarnkar
Participant
Posts: 74
Joined: Wed Jan 11, 2006 2:22 am

Post by swarnkar »

anbu wrote: In ODBC write a user defined sql to delete the table.
I belive, you have to define a dummy column in ODBC stage and need to Use/Handle the same in you user defined SQL, in order to pass the control from transformer stage to ODBC stage.

Thanks,
Nitin Swarnkar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Unlike any other stage, ODBC doesn't care if you don't bind all of the columns in your link into the SQL. So yes, you'll need at least one field in the link but you won't need to use it anywhere.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Mikey
Participant
Posts: 32
Joined: Fri Jan 15, 2010 3:21 pm

Post by Mikey »

Rather than using a Transformer-->ODBC, is it possible to reverse this to ODBC(Delete)-->Transformer-->ODBC(Insert)? I need the Insert step to be dependent on a successful delete. By the way, the transformer has 2 inputs; the hash file to insert & the delete link with a dummy column. I keep getting an error stating there's an incorrect number of result columns on the Delete....there's gotta be an easier way to do this! Right?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No you'd still need something to trigger the first ODBC stage. You may as well use a Before SQL in the target ODBC stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Mikey
Participant
Posts: 32
Joined: Fri Jan 15, 2010 3:21 pm

Post by Mikey »

Thanks for all the feedback; it's working now. I used the Transformer-->ODBC method with a dummy record as posted initially; that seemed to be the cleanest or most inituitive. I looked for the "before/after SQL" tabs that were mentioned, but I don't think they're available with ODBC connections.
Post Reply