Reset MySQL Auto-Increment

Out of curiosity, if there a total of 10 db entries but 5 of those
have been deleted it creates gaps (see below); is it possible to
reassign the entries to have an unbroken id numbering order when one
is deleted? I’m guessing this is just the nature of things and that
once an id is used that’s it. In any case I couldn’t find anything in
my PHP Fat Book™ regarding this specifically.

1
2
3
9
10

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You don’t need to worry about this, it is best left. You could run a
script to adjust this but it is more hassle than it is worth and if
there are other tables that relate to the id’s then it gets even more
complicated if only slightly.

On Jan 12, 2009, at 3:06 PM, Todd wrote:

Out of curiosity, if there a total of 10 db entries but 5 of those
have been deleted it creates gaps (see below); is it possible to
reassign the entries to have an unbroken id numbering order when one
is deleted? I’m guessing this is just the nature of things and that
once an id is used that’s it. In any case I couldn’t find anything
in my PHP Fat Book™ regarding this specifically.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Mike. I don’t really need or want to do it but was just
wondering if it were in fact possible.

Todd

On Jan 12, 2009, at 8:11 AM, Mike B wrote:

You don’t need to worry about this, it is best left. You could run a
script to adjust this but it is more hassle than it is worth and if
there are other tables that relate to the id’s then it gets even
more complicated if only slightly.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes it is possible to use them again, although the auto increment for
the table will increment the column entries one after the other and
not as what is free before the last auto incremented number.

On Jan 12, 2009, at 3:16 PM, Todd wrote:

Thanks Mike. I don’t really need or want to do it but was just
wondering if it were in fact possible.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

If you empty the table with TRUNCATE TABLE table_name; then you will
reset the counter (to 1). There is also a query that can do it in
place, setting the auto-increment counter to an arbitrary number. But
as Mike said, it’s not really a good idea to mess with auto-numbers,
because there may be dependencies.

Walter

On Jan 12, 2009, at 9:22 AM, Mike B wrote:

Yes it is possible to use them again, although the auto increment
for the table will increment the column entries one after the other
and not as what is free before the last auto incremented number.

On Jan 12, 2009, at 3:16 PM, Todd wrote:

Thanks Mike. I don’t really need or want to do it but was just
wondering if it were in fact possible.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options