Page 1 of 1
Mysql Proble: Resetting AutoIncrement Field ?
Posted: Sun May 11, 2003 9:11 pm
by infolock
Hi, Just having a small n00b problem I guess.. I Currently have a MySQL database, and within the table there is an AutoInc field..
The problem is, when I delete rows from the table, the Inc does not update to respond to the chances. In other words, let's say I have 5 rows, and the autoinc field name is ID ( so ID has values 1,2,3,4,5 in each row ). If I delete one row and insert a new field, the new ID value is 6 instead of 5.
Is there a way to have autoinc count backwards, or reset completely ? and if so, could someone give me an example ( either a query or a php snipet ). Thanks a bunch..
Posted: Sun May 11, 2003 9:17 pm
by volka
that's the(/one) purpose of an autoincrement field. You delete records but still all other and future records can be identified by their (unique) autoincrement-id. It's simply a hidden counter, incremented each time a record has been added.
Why do you need it to be stepless?
Posted: Sun May 11, 2003 9:30 pm
by infolock
I dunno, it's just annoying to me to have an empty row table, and then my first entry having to start out where the increment stopped last, instead of starting over like it should. I mean, if the row was deleted, there is no reason to why future records could be identified by their (unique) autoincrement-id if it won't exist..
do you see what I mean?
example:
When I add a user named bob, ID is set to the incremental field that is available.
I then add 15 other users.
I then delete bob, but the ID fields for all the users that remain stay the same, thus leaving out numbers that would be there if it would just adjust he database.
( example database before I delete bob ).
ID | Fname | Lname
-----------------------
01 | David | Henry
02 | David | Stevens
03| Bob11 | Gravy
04| Steven | Something
( example database before I delete bob ).
ID | Fname | Lname
-----------------------
01 | David | Henry
02 | David | Stevens
04| Steven | Something
See, it skips 3, and if any other records are created, it starts at 5, leaving a very disorganized looking table.
Posted: Sun May 11, 2003 9:45 pm
by volka
The id might have been used as referer by other records/tables. This feature is not about making it easier for humans to read the table-data

Posted: Sun May 11, 2003 10:54 pm
by infolock
doh
