* Tobias Asplund
> On Tue, 20 Jan 2004, Marco Paci wrote:
>
> > Since the process of inserting a new record and reading its PK field
> > value is a two step process implemented by:
> > 1) insert into tablename (columnnames) values(....)
> > 2) select last_insert_id()
> > ,and since because of the architecture of my application I cannot
> > prevent that 2 concurrent insertions won't be done
>
> http://www.mysql.com/doc/en/LOCK_TABLES.html
>
> What will happen is:
>
>    |    Write-lock on table
>    |    Insert a new record
[...]

You seem to be saying that he needs to lock the table?

That is wrong. The LAST_INSERT_ID() function is created specifically for
this purpose, it will return the id of the last auto_increment record
inserted by THIS connection. Two simultaneous users will have two different
connections, thus the LAST_INSERT_ID() will return the correct id for both
(or any number of) users, regardless of who executed the first/last INSERT.

<URL: http://www.mysql.com/doc/en/Information_functions.html#IDX1388 >
<URL: http://www.mysql.com/doc/en/ANSI_diff_Transactions.html#IDX141 >

--
Roger


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

Reply via email to