S
S
StrangeAttractor2014-08-11 23:19:21
MySQL
StrangeAttractor, 2014-08-11 23:19:21

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

2 answer(s)
J
Julia, 2014-08-12
@saltiveratia

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.

O
Optimus, 2014-08-12
Pyan @marrk2

You will not have a random access to a remote record and instead of a remote one in one place it will issue another one, but because everything will move, everything will not get mixed up? In CMS, for example, this is so))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question