AUTO_INCREMENT Mysql problem

Asked

Viewed 598 times

0

I had a problem that from the ID 35218, the accounts started to be inserted from the ID 400000, but I do not remember having touched the value of AUTO_INCREMENT. What can I do to get the accounts back to lower empty ID?

inserir a descrição da imagem aqui

  • What probably happened is some high number insertion, probably 400000, which automatically increased the increment. The autoincrement will always be higher, nor would it have made sense to want to go back to the previous number. What is the problem in leaving as it is? Autoincrement was not meant to be sequential, but unique.

  • Back to follow the same sequence.

1 answer

3

First of all you should check if there is any problem in your insertion, using an exception block, when you try to insert something and some error occurs, even so the sequence changes, it is possible to modify the sequence of the auto_increment of your table using the code:

ALTER TABLE nome_da_tabela AUTO_INCREMENT = 352019;

The problem is that if you do this there will come a time when it will reach the number: 400000, and if the field is a primary key you will have problems as you will be violating a single key.

  • I’ve already done this, the question is which lines have inserted in these larger numbers, to convert them to the smallest free number.

  • 1

    What is the need to convert to the smallest free number, this table has relationship with other tables, IE, the key field is Foreign key in other tables? If so, I advise you not to touch it...

  • Because I intend to change the maximum number of Ids to 100,000, and with these high numbers it gets weird

Browser other questions tagged

You are not signed in. Login or sign up in order to post.