Hi Kevin,

> I'm converting a database from a filesharing based technology to mySQL. The
> database has its own column type called Sequence which is the same as using
> the AUTO_INCREMENT property. I'd like to use AUTO_INCREMENT if possible but
> I'm not really sure what I can do with it - can anybody help with the
> following:
>
> 1. How does LAST_INSERT_ID() work?
> Can I find out the last ID I created on a specific table and will this
> return the correct value if multiple users are inserting into the tables?

Define "correct"!? It returns the ID of the row most recently INSERTed during this 
connection - which suits
foreign key formation in secondary tables. This is distinct from providing the highest 
numbered ID currently in
the table.

RTFM:  8.4.3.126  mysql_insert_id()
- which is not tremendously informative...

> 2. I need to import data into the tables and do not want mySQL to re-create
> the ID values for these records. How can this be achieved?

Suggested approach: create the table(s) defining the ID field as a simple integer data 
type, and without any
indexes or keys; perform the import; then use ALTER TABLE (or an administration 
package) to add the indexes and
start off the AUTO_INCREMENT cycle from the correct ID value.

RTFM: 6.4.3  INSERT Syntax
3.5.9  Using AUTO_INCREMENT
6.5.3  CREATE TABLE Syntax
6.5.4  ALTER TABLE Syntax

Regards,
=dn



---------------------------------------------------------------------
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