On Mon, 15 Dec 2003, Paul Fine wrote:

> If I have a table like with a column being the PK for the table and being an
> Auto Increment value, what is the best way to return this value to my
> script?

If you insert a row LAST_INSERT_ID() will return the primary key value in
this setup.

The other way is if you're not inserting a record, but just want to know
the next value that will be used.
SHOW TABLE STATUS LIKE '<tablename>';


> It is possible that additional rows may have been added during the
> small wait.

It is possible another value is inserted in between the query for the next
number and an insert afterwards.
To stop this from happening you can place a read-lock on the table, this
won't allow any other processes to insert rows until you release the lock.

LOCK TABLE <tablename> READ;
Get Auto-increment value

Do your stuff...

UNLOCK TABLES;

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

Reply via email to