Four Stars

How to get last inserted primary key mysql database

Hi All,

I'm tryring to store old data into mysqql database from csv files,
I have two tables mother and Daughter, both have auto_increment id:

table 1 : id, fname, lname .. etc

table 2 : id, id_table1 

after storing a row in table1 I should store it's primary key in table2.

In the photo below table1 is "responsable" and table2 is "agent_suivi"

the method "Select Last_Insert_id()" didn't work for me because I don't have other attributes to store I have only the id of the table mother , so using the map directly requires at least one column to link between tmap and tmysqloutput.
How can I do it?

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: How to get last inserted primary key mysql database

Hi 

 

You have to use tmysqllastinsertid component to bring last inserted value for next step. I have attached component image also

 

hope it will help to resolve ur problem

 

I checked for mssql same kind of component worked fine.

 

 

 

5 REPLIES
Nine Stars

Re: How to get last inserted primary key mysql database

Is this something what could work?

SELECT `AUTO_INCREMENT`
FROM  INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DatabaseName'
AND   TABLE_NAME   = 'TableName';

 

Four Stars

Re: How to get last inserted primary key mysql database

I don't know how to use it.

Actually, I'm blocked between the "tMysqlOutput" of the table mother and the "tMysqlInput" of the other table in which I want insert the last inserted ID in the table motherCapture3.PNG

My question is how to link between these two components and store the id retrieved from the first one to the second?

Nine Stars

Re: How to get last inserted primary key mysql database

Why not create a second responsable out from tMap_1 and define your own prim_key.
Does it need to be auto_increment, you could use a talend increment function in tMap by using the routines.

Six Stars

Re: How to get last inserted primary key mysql database

Hi 

 

You have to use tmysqllastinsertid component to bring last inserted value for next step. I have attached component image also

 

hope it will help to resolve ur problem

 

I checked for mssql same kind of component worked fine.

 

 

 

Four Stars

Re: How to get last inserted primary key mysql database

I used the "tMysqlLastInsertedId" and it worked 

Thank you for your help.

Capture4.PNG