Skip to main content

Inserting data in parent/child tables

The following Job is dedicated to advanced database users, who want to carry out multiple table insertions using a parent table Table1 to generate two child tables: Name and Birthday.

For more technologies supported by Talend, see Talend components.

  • In Access 2007, create an Access database named Database1.

  • Once the Access database is created, create a table named Table1 with two column headings: Name and Birthday.

Back into the Integration perspective of Talend Studio , the Job requires twelve components including tAccessConnection, tAccessCommit, tAccessInput, tAccessOutput and tAccessClose.

  • Drop the following components from the Palette to the design workspace: tFileList, tFileInputDelimited, tMap, tAccessOutput (two), tAccessInput (two), tAccessCommit, tAccessClose and tLogRow (x2).

  • Connect the tFileList component to the input file component using an Iterate link. Thus, the name of the file to be processed will be dynamically filled in from the tFileList directory using a global variable.

  • Connect the tFileInputDelimited component to the tMap component and dispatch the flow between the two output Access components. Use a Row link for each of these connections representing the main data flow.

  • Set the tFileList component properties, such as the directory where files will be fetched from.

  • Add a tAccessConnection component and connect it to the starter component of this Job. In this example, the tFileList component uses an OnComponentOk link to define the execution order.

  • In the tAccessConnection Component view, set the connection details manually or fetch them from the Repository if you centrally store them as a Metadata DB connection entry. For more information about Metadata, see Managing metadata in Talend Studio.

  • In the tFileInputDelimited component's Basic settings view, press Ctrl+Space bar to access the variable list. Set the File Name field to the global variable: tFileList_1.CURRENT_FILEPATH. For more information about using variables, see Using variables in a Job or Route.

  • Set the rest of the fields as usual, defining the row and field separators according to your file structure.

  • Then set the schema manually through the Edit schema dialog box or select the schema from the Repository . Make sure the data type is correctly set, in accordance with the nature of the data processed.

  • In the tMap Output area, add two output tables, one called Name for the Name table, the second called Birthday, for the Birthday table. For more information about the tMap component, see tMap operations.

  • Drag the Name column from the Input area, and drop it to the Name table.

  • Drag the Birthday column from the Input area, and drop it to the Birthday table.

  • Then connect the output row links to distribute the flow correctly to the relevant DB output components.

  • In each of the tAccessOutput components' Basic settings view, select the Use an existing connection check box to retrieve the tAccessConnection details.

  • Set the Table name making sure it corresponds to the correct table, in this example either Name or Birthday.

  • Select Default from the Action on table drop-down list. This is because the tables already exist and no operation is needed for the tables.

  • Select Insert as Action on data for both output components.

  • Click on Sync columns to retrieve the schema set in the tMap.

  • Then connect the first tAccessOutput component to the first tAccessInput component using an OnComponentOk link.

  • In each of the tAccessInput components' Basic settings view, select the Use an existing connection check box to retrieve the distributed data flow. Then set the schema manually through Edit schema dialog box.

  • Then set the Table Name accordingly. In tAccessInput_1, this will be Name.

  • Click on the Guess Query.

  • Connect each tAccessInput component to tLogRow component with a Row > Main link. In each of the tLogRow components' basic settings view, select Table in the Mode field.

  • Add the tAccessCommit component below the tFileList component in the design workspace and connect them together using an OnComponentOk link in order to terminate the Job with the transaction commit.

  • In the basic settings view of tAccessCommit component and from the Component list, select the connection to be used, tAccessConnection_1 in this scenario.

  • Save your Job and press F6 to execute it.

The parent table Table1 is reused to generate the Name table and Birthday table.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!