[ale] Auto increment in MySQL

James P. Kinney III jkinney at localnetsolutions.com
Wed Sep 14 23:49:57 EDT 2005


On Wed, 2005-09-14 at 22:55 -0400, Grant Robertson wrote:
> No, it will use the highest auto value in use at the time of alter in
> that table, plus one. It would be a pretty bad idea for it to do much
> else.

I stand corrected. I just tested this and found the following results:
Manually setting AUTO_INCREMENT to a value lower than the highest in
actual use will result in the value being changed by the system as soon
as it is access next.

So I found this by creating a test db with 2 columns, id
(auto_increment) and name. I stated with id=1. I then inserted values
for name and ran the counter in id up to 6. Then I set the
AUTO_INCREMENT value to 3. On the next insert, the AUTO_INCREMENT jumped
up to 8, the new row had a value of 7.

So the system does a MAX on the column and only store the AUTO_INCREMENT
value as a perk.

Now if I changed the value to one higher than currently in use, it kept
it and used it. But when I reset it back to a lower value (in
particular, one that had been skipped) it reset to the MAX+1 value as
earlier.
> 
> -G
> 
> On 9/14/05, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
> > On Wed, 2005-09-14 at 21:34 -0400, George Carless wrote:
> > > ALTER TABLE theTableInQuestion AUTO_INCREMENT=1234
> > >
> > 
> > Here is a question.  Lets say that I have a bunch of holes because I
> > deleted various rows.  can I set the value to 1 and MySQL will be smart
> > enough to fill those holes?
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
-- 
James P. Kinney III          \Changing the mobile computing world/
CEO & Director of Engineering \          one Linux user         /
Local Net Solutions,LLC        \           at a time.          /
770-493-8244                    \.___________________________./
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part




More information about the Ale mailing list