last_insert_id()

This is a discussion on last_insert_id() within the MySQL Database forums, part of the Database Forums category; Anyone out there have a working snippet of code using last_insert_id() to grab the last inserted record id? I've ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-11-2007
Bob Imperial
 
Posts: n/a
Default last_insert_id()

Anyone out there have a working snippet of code using last_insert_id()
to grab the last inserted record id? I've been trying to for the last
hour and get nuttin but errors so far. I'm using coldfusion too btw, I
have song_id which is my PK and I can pull the ids using SELECT * just
fine, but the minute I try to do last_insert_id(song_id) it bombs. I
guess I'm just not understanding how to use it....seeing the proper
syntax would be great if possible.
TIA

Bewildered Bob

Reply With Quote
  #2 (permalink)  
Old 03-11-2007
Gordon Burditt
 
Posts: n/a
Default Re: last_insert_id()

>Anyone out there have a working snippet of code using last_insert_id()
>to grab the last inserted record id?


Example:
SELECT LAST_INSERT_ID();

OR
INSERT INTO tablea (....) VALUES (....); Do the insert.
INSERT INTO tableb (parent_id, detail 1, detail2) VALUES
( last_insert_id(), 'XYZ', '1234'); Refer to tablea.

>I've been trying to for the last
>hour and get nuttin but errors so far. I'm using coldfusion too btw, I
>have song_id which is my PK and I can pull the ids using SELECT * just
>fine, but the minute I try to do last_insert_id(song_id) it bombs. I


Don't use an argument for last_insert_id(). I think that's mostly
used for replaying binary logs from an old backup and transaction logs.

Note: you don't get to select which table. It's the last inserted
id for your connection (you don't have to worry about someone else
doing inserts at the same time) for *any* table. If you want the
id for a table you just inserted to, grab the value before doing
more inserts.

Reply With Quote
  #3 (permalink)  
Old 03-11-2007
Brian Wakem
 
Posts: n/a
Default Re: last_insert_id()

Bob Imperial wrote:

> Anyone out there have a working snippet of code using last_insert_id()
> to grab the last inserted record id? I've been trying to for the last
> hour and get nuttin but errors so far. I'm using coldfusion too btw, I
> have song_id which is my PK and I can pull the ids using SELECT * just
> fine, but the minute I try to do last_insert_id(song_id) it bombs. I
> guess I'm just not understanding how to use it....seeing the proper
> syntax would be great if possible.
> TIA
>
> Bewildered Bob



http://dev.mysql.com/doc/refman/5.0/...functions.html

Scroll down to LAST_INSERT_ID()


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0