469,279 Members | 2,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

autoincrement

Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
that "X" icon) the last three (3) records. Then I run a PHP script to
add 3 records to the DB. I have an autoincrement PK field and I'm using
mysql_insert_id to add fields in other tables subsequently...Well, the
auto-increment starts at 21. Here's my question:

What would be the method to just at the end (ie. 18-20) "really" delete
those "ghost" records or reset somehow so that auto-increment knows to
start at 18 again.?

I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
if possible.
Jul 20 '05 #1
3 2444

"leegold2" <le*****@nospam.net> wrote in message
news:VWTDd.1296$F97.973@trnddc06...
Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
that "X" icon) the last three (3) records. Then I run a PHP script to add
3 records to the DB. I have an autoincrement PK field and I'm using
mysql_insert_id to add fields in other tables subsequently...Well, the
auto-increment starts at 21. Here's my question:

What would be the method to just at the end (ie. 18-20) "really" delete
those "ghost" records or reset somehow so that auto-increment knows to
start at 18 again.?

I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
if possible.


Auto-increment fields are mostly used for relationships between tables so
deleting records and taking those vacant numbers for the new entered data
would link this new record to some other record in some other table that is
not meant to be linked to at all. It causes serious relationship problems
and therefore it is (I think and am not completely sure) not supported.

Jonathan
Jul 20 '05 #2
leegold2 wrote:
What would be the method to just at the end (ie. 18-20) "really" delete
those "ghost" records or reset somehow so that auto-increment knows to
start at 18 again.?


Here's an excerpt from
http://dev.mysql.com/doc/mysql/en/ex...NCREMENT.html:

"Note that in this case (when the AUTO_INCREMENT column is part of a
multiple-column index), AUTO_INCREMENT values will be reused if you
delete the row with the biggest AUTO_INCREMENT value in any group. This
happens even for MyISAM tables, for which AUTO_INCREMENT values normally
are not reused.)"

So it sounds like you can't reuse the auto-generated values, unless they
are part of a compound (multi-column) key.

Regards,
Bill K.
Jul 20 '05 #3
Jonathan Martens wrote:
"leegold2" <le*****@nospam.net> wrote in message
news:VWTDd.1296$F97.973@trnddc06...
Say I got 20 records in a MYSQL DB. I go into PHPMyAdmin and drop (it's
that "X" icon) the last three (3) records. Then I run a PHP script to add
3 records to the DB. I have an autoincrement PK field and I'm using
mysql_insert_id to add fields in other tables subsequently...Well, the
auto-increment starts at 21. Here's my question:

What would be the method to just at the end (ie. 18-20) "really" delete
those "ghost" records or reset somehow so that auto-increment knows to
start at 18 again.?

I got no problem with holes (ie. 1,2..5,6) but i want stuff at the wiped
if possible.

Auto-increment fields are mostly used for relationships between tables so
deleting records and taking those vacant numbers for the new entered data
would link this new record to some other record in some other table that is
not meant to be linked to at all. It causes serious relationship problems
and therefore it is (I think and am not completely sure) not supported.


Right i understand that now. thanks!


Jonathan

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Fabio Negri Cicotti | last post: by
reply views Thread by Neil | last post: by
6 posts views Thread by Dennis | last post: by
5 posts views Thread by JC Voon | last post: by
4 posts views Thread by Tim | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.