Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting - getting back the AutoInc Number

Status
Not open for further replies.

Coderifous

Programmer
Joined
Dec 13, 2001
Messages
782
Location
US
When I'm inserting into a table that has the AutoIncrement as the Primary Key, I'd like to get that value returned to me. I'm using the Perl DBI. I'd like to think that there is a function that does this, but I don't know it.

--jim
 
I have never used the Perl DBI, but the MySQL way of doing it is "SELECT LAST_INSERT_ID();". //Daniel
 
i'm not familiar with perl but mysql has function LAST_INSERT_ID() which returns the id of the last inserted row (assuming there's an autoincremented column)
so after running the insert query, use SELECT LAST_INSERT_ID();

this is returned on a perconnection basis, so you may have multiple users insert data, but the returned id is from the row you have entered
 
Very nice fellas. That'll do.

Thanks.

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top