Don't forget that if you "commit" then last_insert_id will return 0

----- Original Message ----- 
From: "William R. Mussatto" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 24, 2003 6:56 PM
Subject: Re: last_insert_id()


: R.Dobson said:
: > Hi,
: >
: > Is it possible to obtain the last_insert_id() for a particular column in
: >  a particular table?
: > eg, say i wanted to obtain the last insert id of a column called id in
: > table reference, something along the lines of:
: >
: > last_insert_id(reference.id)
: >
: > The reason I ask is because I want to initially insert values into two
: > tables and then insert values into a third using the last_insert_id()
: > from the first two tables. Obviously, the last_insert_id from the first
: > insert is replaced by the last_insert_id from the second insert. This is
: >  all done in a perl script and I could store the first last_insert_id in
: >  a variable but I thought their might be a more elegant way round it?
: >
: > tia
: > Rich
: last_insert_id is connection specific and contains the value of the
: auto-increment column for the last record you inserted using that
: connection.  The sequence is
: - do insert of record with auto-increment column
: - get value of last_insterted_id (i.e., the value asigned to the
: auto-increment column to that record).  There is only one column so there
: is no need for figuring out which column.
:
: If you do two inserts you must get the last_inserted_id BETWEEN the
: inserts.  If the second table also has a auto-increment column you will
: have to get its value after that insert.
:
: Hope this helps.
:
: William R. Mussatto, Senior Systems Engineer
: Ph. 909-920-9154 ext. 27
: FAX. 909-608-7061
:
:
:
: -- 
: MySQL General Mailing List
: For list archives: http://lists.mysql.com/mysql
: To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]
:
:


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to