BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Index AutoIncrement in MYSQL

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop)
View previous topic :: View next topic  
Author Message
kenshiro2000
Guest





PostPosted: Fri Dec 12, 2003 11:19 am    Post subject: Index AutoIncrement in MYSQL Reply with 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
Back to top
Jayme Jeffman Filho
Guest





PostPosted: Fri Dec 12, 2003 4:25 pm    Post subject: Re: Index AutoIncrement in MYSQL Reply with quote



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" <kenshiro2000 (AT) libero (DOT) it> wrote

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


Back to top
Scott Metzger
Guest





PostPosted: Fri Dec 12, 2003 4:45 pm    Post subject: Re: Index AutoIncrement in MYSQL Reply with quote



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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.