Page 1 of 1

Mysql delete (auto_increment)

Posted: Mon Aug 23, 2004 8:10 pm
by Pizmal
I have a question on how mysql works. If i have a PK that is auto_increment numbers....

example

1 .. 2 .. 3 .. 4 .. 5

If i delete 3. I understand 6 would be the next number. Why does it go

1 .. 2 .. 6 .. 4 .. 5


??

Thanks for you info

From
Pizmal

Posted: Mon Aug 23, 2004 8:18 pm
by tim
b/c thats the way it is, it cannot reset all the numbers b/c one row is deleted.

however, if there be a need to do something to that effect, mySQL has the function:

TRUNCATE

Posted: Mon Aug 23, 2004 8:20 pm
by Pizmal
I dont want to reset the numbers just dont want that number in the wrong order. If that is how it is .... I guess everyone "coding people" use php or scripting to reorder them with some sort of sort() ?

From
Pizmal

Posted: Mon Aug 23, 2004 8:35 pm
by feyd
6 will probably appear there because that's the most efficient place to stick the information.. remember mysql is trying to minimize storage space required.. if you used ORDER BY that id, then it'll always appear in order of inserts..

Posted: Mon Aug 23, 2004 8:43 pm
by Pizmal
That is what I wanted to know. I have problems determining if that is how it is suppose to act.

From
Pizmal

Posted: Mon Aug 23, 2004 8:59 pm
by feyd
just use ORDER BY..