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..
Mysql Proble: Resetting AutoIncrement Field ?
Moderator: General Moderators
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.
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.