auto_increment change
Moderator: General Moderators
auto_increment change
How can i change the auto_increment value manualy for a table?
When i delete rows from a table the auto_increment doesnt change and that a bit annoying. Can is there a way to change it manually?
Is there any trick to use in order to set auto_increment value to fill in the gaps? For example i have the value id, and have 5 records with id 1,2,3,4,5. I delete record 4 and i want next time, the added record to get id 4, while the next from that gets id 6...Is that possible?
When i delete rows from a table the auto_increment doesnt change and that a bit annoying. Can is there a way to change it manually?
Is there any trick to use in order to set auto_increment value to fill in the gaps? For example i have the value id, and have 5 records with id 1,2,3,4,5. I delete record 4 and i want next time, the added record to get id 4, while the next from that gets id 6...Is that possible?
One rule about a primary key is that it never ever gets reused or changed. This behaviour is by design when using auto increment as a primary key. I don't know how to make it function otherwise.
What exactly are you trying to do anyways? There should be another way to accomplish the functionality you want.
What exactly are you trying to do anyways? There should be another way to accomplish the functionality you want.
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
Exactly - you don't want to muck around with it - leave it be and let it work as designed. Even if phpMyAdmin will let you, don't - you are just asking for trouble and you will no doubt break something and have to have your tables restored from backups...feyd wrote:It's not supposed to change and you aren't supposed to change it. Numbers it generates are not supposed to repeat, ever. If you want to fill in gaps and so forth you shouldn't be using an automatically incremented field.
Think of a more creative solution to what you are trying to accomplish.
fv
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
Maybe it won't actually "break" the DB, but could easily break relationships with other tables, and by virtue of that, applications that use that/those tables! Plus I don't know what the effect on existing rows would be if the start value, increment or decrement,and increment/decrement amount were changed, nor what would happen with a reload of data from a backup afer such was done.
fv
fv
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas