Answer the question
In order to leave comments, you need to log in
How to tamp identifiers in MySQL?
Let's say there are several tables that use auto-increment identifiers. Foreign keys and referential integrity control are actively used between tables (but you can turn off the database for a while). We added elements, some of them were removed, we work further, "holes" appeared in the numbering order. It is necessary to decrease all IDs (and the counter for the next new ID) so that the numbering becomes continuous again.
How to do this (other than the obvious option of writing your own program that will do all this "manually")?
The question "why is this necessary?" let's leave it in offtopic, it's clear that this is almost never necessary, especially in production, but still interesting, in certain contexts it makes sense.
Answer the question
In order to leave comments, you need to log in
Probably triggers. And it would be nice to ask the database before writing a new field about the number of the largest previous one and assign the next one.
The program will not work, you will get a mysql function for a couple of lines.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question