0

I have designed a Talend job to copy data from excel file to the SQL Server tables. Before copying the data I am using one stored procedure defined in a database to clear already existing entries in a database so that it don't get repeated.

But since I would be doing data transformation to the database which might not be having this stored procedure my data transformation won’t work properly.

So I want to define stored procedure in my Talend job itself.

Which component should I use and How I do I do this?

Quick-gun Morgan
  • 338
  • 12
  • 31

2 Answers2

1

use tSQLRow component to execute SQL statement, you can execute PLSQL statement in tSQLRow component.

UmeshR
  • 803
  • 1
  • 9
  • 16
  • I am confused between tMSSqlSP and tMSSqlRow. – Quick-gun Morgan Jun 05 '14 at 12:55
  • as the name indicate one is used to execute `tMSSqlSP ` store procedure and other one `tMSSqlRow` used to execute SQL statement like delete, update, select.. – UmeshR Jun 05 '14 at 14:19
  • I am using the query.. "delete from table1, table2, table3" But its not working. All the data gets copied and at last it gives an error which says "incorrect syntax near ',' " However if I use query "delete from table1" It works. Would I have to use multiple tMSSQLRow? Each for a table. – Quick-gun Morgan Jun 05 '14 at 14:26
  • I found it here. https://help.talend.com/display/KB/Executing+multiple+SQL+statements+with+one+tMysqlRow+component Thanks. – Quick-gun Morgan Jun 05 '14 at 14:32
0

The Talend txxxSqlOutput components give you an option to change the default "action on table" and one of these options is to clear the table or truncate it (see here for the differences). Alternatively, if you are wanting to initalise the database for the load of data every time and you don't need preprepared tables and custom indexes then you could use the drop table if exists and create option to start afresh each time. The only problem with that option is that it won't do more than create a PK index, do datatypes, set lengths and set nullable/not nullable on fields. So if you need to add a lot of indexes in then you will lose those but then you could always add the indexes back in later and this would have the benefit of speeding up your initial insert too.

As always, you can use a database row component for executing custom SQL against the database and this includes DELETEs, TRUNCATEs and ALTERs but I'd be inclined to use the graphical components that Talend provides wherever possible as it keeps the logic from filtering down to a separate level. You could use an ALTER statement to set up indexes/complex keys after using a CREATE statement in your inital DB output component too.

As a side note, I wouldn't put that kind of SQL statement into a stored procedure unless you have a requirement that no application performs ad-hoc SQL statements on the database and everything must be done by calling a sproc. This is typically only the case in public facing applications where it will be done for security reasons and allowing a DELETE statement to be triggered externally sounds like a bad idea.

Community
  • 1
  • 1
ydaetskcoR
  • 53,225
  • 8
  • 158
  • 177