469,106 Members | 2,258 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,106 developers. It's quick & easy.

How to get the last auto increment key value for child tables

Hi,

How to find out the last insert primary key value when a field is auto
incremented. Select the maximum value from the table is not an option
because users can add rows very quickly.

First I have to insert the values for table t_id. The value of id is needed
to insert for table t_idreply. How to
get the primary key value for t_id ?

CREATE TABLE `t_id` (
`id` bigint(20) NOT NULL auto_increment,
`subject` varchar(128) NOT NULL default '',
PRIMARY KEY (`id`),
) TYPE=MyISAM AUTO_INCREMENT=1;

CREATE TABLE `t_idreply` (
`id` int(11) NOT NULL default '0',
`volgnr` int(11) NOT NULL auto_increment,
`reply` longtext,
PRIMARY KEY (`id`,`volgnr`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

Thanks a lot

Johan
Jul 19 '05 #1
2 20474
Johan den Boer wrote:
Hi,

How to find out the last insert primary key value when a field is auto
incremented. Select the maximum value from the table is not an option
because users can add rows very quickly.


Manual helps:

http://www.mysql.com/doc/en/Getting_unique_ID.html

Jul 19 '05 #2
Johan den Boer wrote:
Hi,

How to find out the last insert primary key value when a field is auto
incremented. Select the maximum value from the table is not an option
because users can add rows very quickly.


Manual helps:

http://www.mysql.com/doc/en/Getting_unique_ID.html

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by David P. Donahue | last post: by
3 posts views Thread by Chris | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.