Hi Michael

01.02.02 16:27:24, "Fochtman, Michael" <[EMAIL PROTECTED]> wrote:

>BMJI,
>
>But isn't 'last_insert_id()' only meant to be called after inserting a
>record??  If you've never inserted a record (using the current connection),
>it seems like calling 'last_insert_id()' would be a meaningless call.  It
>could return the highest value of the auto-increment column, but it could
>just as easily return -1 or 0 or Avagadro's number.

just as you say, if you didn't create a new (autoincremented) record, there 
will be NO last_insert_id().
the name of the function already tells what it's supposed to do.
if you ever call it BEFORE any autoincrementing INSERT, it will return 0 .

>I thought it was only meant to retrieve the value that is automatically
>inserted into an auto-increment column.  The column isn't supposed to be set
>by the INSERT statement, the backend engine will figure out the next
>available number and put it in.  

yes and no.
normally you won't set the value explicitly, you want to get the next automatically 
generated value.
but you MAY set a new starting point for the sequence.
this is sometimes required!
e.g.: if you ever transfer data from one to another DB, you will have to initialize 
the counter properly.

>But the client can't know in advance what that value is going to be.  So if
>the client needs to know what was 'decided' by the engine, it can call
>'last_insert_id()' AFTER inserting the record.

yes.

>
>Or am I all wet here...
>
>Mike Fochtman

[removed tho whole quoted original]

please, don't append the whole original mail if you don't 
want to use it for citation.

regards
Andreas

mysql, sql, select


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to