By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.