Job to trucate tables

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
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Job to trucate tables

Post by dsdeveloper123 »

Hi,

I pretty new to datastage. So the question I am posting might be very silly.

I have a scenario where in I have to clear all the tables before inserting. I know there is a option like truncate and insert. But what I want to know is, if there is some other solution to this problem. Can I have a job in the sequencer which will I can call first in the sequence so that I can clear all the tables.

Thank you in advance!!!
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

oh yes, you have many ways to do it. you can choose best of that.
you can have a routine, to truncate the table, and call it before the insert job.
you can also have a job to delete records from table. before this insert job.

there may be some other silly methods :lol:
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Thank you...
I m calling a user defined sql file which will delete all the tables I use.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Ooppss...
want to know something...
can i use ExecCommand in the job sequencer to execute a sql file which can truncate the tables
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure, any script you can write can be run from the Execute Command stage... but are you sure that's the right approach? With the truncate built into the load job, it can be easily restarted. However, what if your load fails and the solution is to truncate again? Now you've got to find a way to rerun the truncate step, which will probably mean a manual step.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Got ur point...
I am going with truncate and insert option..
Thank u
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

Alternatively : create a stored procedure that clears data in your tables. Create a job that has a stored proc stage, and and output link to capture the return code and proc message to a sequential file. Call this job first in your sequencer.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

There's multiple ways to accomplish this. A job could source from a transformer, pass no rows to a DB stage and simply perform the 'truncate'. I have a multi-instance job that 'truncates any table' with the InvocationID being the table name. Food for thought.

And a separate truncate step may very well be ok in an 'all or nothing' load strategy - one where the Transaction Size is zero. Make sure you think your design through, not just the running but the restart / recovery as well.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Ok..

Can I call sub-routine from the job properties. So that it calls a sql file to delete the tables. I have a series of insertions. So I want to truncate the tables before my jobs runs in a sequencer.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Ok..

Can I call sub-routine from the job properties. So that it calls a sql file to delete the tables. I have a series of insertions. So I want to truncate the tables before my jobs runs in a sequencer.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Ok..

Can I call sub-routine from the job properties. So that it calls a sql file to delete the tables. I have a series of insertions. So I want to truncate the tables before my jobs runs in a sequencer.
dsdeveloper123
Participant
Posts: 33
Joined: Sun Jun 24, 2007 9:46 pm

Post by dsdeveloper123 »

Ok..

Can I call sub-routine from the job properties. So that it calls a sql file to delete the tables. I have a series of insertions. So I want to truncate the tables before my jobs runs in a sequencer.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No.
No.
No.
No.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
klsrao
Participant
Posts: 7
Joined: Fri Oct 22, 2004 9:07 am

Post by klsrao »

You can do the following steps to avoid truncate when you restart job sequence:

1) Create a sequence "One" with one job that contains Truncate (in any way discussed above).
2) Create another sequence "Two" with rest of the jobs.
3) Run sequence "One" as a separate process.
4) Run sequence "Two" as a separate process after running sequence "One".

If sequence "Two" fails, you need to restart sequence "Two" only.

Lakshmi Srinivas
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? Still curious what's so horrible about the 'Truncate then insert' action most stages support? Unless you are using ODBC, from what I recall it doesn't have that as a selectable 'update action', sticking you with the transactional delete of 'Clear' as your only option there.
-craig

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