Board index » cppbuilder » Index AutoIncrement in MYSQL

Index AutoIncrement in MYSQL


2003-12-12 07:19:51 PM
cppbuilder29
Hi, i'm working with BCB6 on a MYSQL DB. I've defined some tables with primary key of autoincrement type.
Now if i insert a new record, i don't know what is the index that the DB create for me. How can i retrive this index?
I need this beacuse if i have a primary key relationed with a foreign key present in another table, when i insert a new record on the first table i must create a related record on the second table and i must insert the same index.
Is there a SQL command permitting to retrive last index created?
My Application is a client/server application, then the last inserted index is relative to every client, i hope....
tnx
Ken
 
 

Re:Index AutoIncrement in MYSQL

Hello,
From the MySQL manual :
"LAST_INSERT_ID([expr])
Returns the last automatically generated value that was inserted into an AUTO_
INCREMENT column."
You can pass this expression as a query to the MySQL database.
HTH
Jayme.
"kenshiro2000" < XXXX@XXXXX.COM >wrote in message news:3fd9b267$ XXXX@XXXXX.COM ...
Quote

Hi, i'm working with BCB6 on a MYSQL DB. I've defined some tables with primary key of autoincrement type.

Now if i insert a new record, i don't know what is the index that the DB create for me. How can i retrive this index?

I need this beacuse if i have a primary key relationed with a foreign key present in another table, when i insert a new record on the first table i must create a related record on the second table and i must insert the same index.

Is there a SQL command permitting to retrive last index created?

My Application is a client/server application, then the last inserted index is relative to every client, i hope....

tnx

Ken
 

Re:Index AutoIncrement in MYSQL

Assuming your MySQL component is derived from TDataSet or shares the
same functionality you can use InsertRecord to insert a new record.
When you use InsertRecord "The newly inserted record becomes the active
record." You can then read your index value from the active record.
Scott Metzger
 

{smallsort}