Hi,
I want to clear tables using DataStage. The way I do it know is to read an empty table. In the target table I have selected in the update action 'Clear table then insert rows'.
I have the impresion that tables are cleared via the SQL statement delete from while I would prefer truncate table, which is much faster.
Kind regards,
Jan
Clear tables
Moderators: chulett, rschirm, roy
Yes, 'clear' is a transactional delete of all rows in the table.
You don't actually need to read an empty table, any method to send zero rows to the stage will work. For example, starting from a Transformer stage with the constraint set to @FALSE works great. All you need is a bogus stage variable to allow the job to compile.
Then select 'Truncate table then insert rows' if that option is available. Are you using ODBC by chance? In that case, you could use User-Defined SQL I would think.
You don't actually need to read an empty table, any method to send zero rows to the stage will work. For example, starting from a Transformer stage with the constraint set to @FALSE works great. All you need is a bogus stage variable to allow the job to compile.
Then select 'Truncate table then insert rows' if that option is available. Are you using ODBC by chance? In that case, you could use User-Defined SQL I would think.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Dear chulett,
I do not use an empty table anymore to clear/truncate a table.
Using truncate I meet the following problem.
I have two tables TableA and TableB there is a foreign key constraint between the two tables. When I use truncate for TableA it succeeds but when I use truncate for TableB I get the message:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot truncate table 'TableB' because it is being referenced by a FOREIGN KEY constraint.
When I use clear for TableB it is succesfull.
What to do?
Kind regards,
Jan
I do not use an empty table anymore to clear/truncate a table.
Using truncate I meet the following problem.
I have two tables TableA and TableB there is a foreign key constraint between the two tables. When I use truncate for TableA it succeeds but when I use truncate for TableB I get the message:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot truncate table 'TableB' because it is being referenced by a FOREIGN KEY constraint.
When I use clear for TableB it is succesfull.
What to do?
Kind regards,
Jan
That's a database constraint, not a DataStage one. Probably best to talk to your DBA and see what your options are. For example, if you have the grants you need you may be able to disable the FK constraint in the 'before sql' tab, do the truncate and then re-enable it 'after sql'.
Other places setup stored procedures and allow you to call them to do the truncation and that handle fun stuff like FK constraints automagically. Talk to your DBA.
Also, there's no need to contact me offline about answering this new question. Anyone could have answered it, it's not like I have exclusive 'dibs' on the solution. Never mind the fact that I was sleeping when this question and your email came in. Someone will get to you as soon as practical, so have patience.
Other places setup stored procedures and allow you to call them to do the truncation and that handle fun stuff like FK constraints automagically. Talk to your DBA.
Also, there's no need to contact me offline about answering this new question. Anyone could have answered it, it's not like I have exclusive 'dibs' on the solution. Never mind the fact that I was sleeping when this question and your email came in. Someone will get to you as soon as practical, so have patience.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers