Click to See Complete Forum and Search --> : Accessing newly created primary key in MySQL using PERL


compbrat75
12-17-2004, 10:29 PM
Hello Fellow Forumites!

I know this has probably been asked and solved before on this board and I did try to search for it; however, the search feature will not accept a word with less than 4 letters. So, I can't search for the word 'key' as in Primary Key. :confused:

I have a PERL script that adds a record to a MySQL database table and thus creates a Primary Key for that record. I need to then access that newly created Primary Key to use as a value to insert into another associated table in order to link the two records in the two tables. Since it is entirely possible that a record with the same information is created twice (which is allowable in this script)I cannot pull the key by using some of the information that was just inserted without risking the return of the incorrect Primary Key.

Is there anyone that can help me grab the newly created Primary Key?

Any help is, of course, appreciated - no, wait - treasured. :D

Nedals
12-17-2004, 11:25 PM
Check out LAST_INSERT_ID()
I don't have my mySQL book at home and my memory's shot, :)
but I'm pretty sure that will solve your problem.

compbrat75
12-17-2004, 11:31 PM
Hi Nedals,
Bless you, dear. Bless you. :D
compbrat75