Suppose there is a table table with the fields id and name . There are five entries in it, our id is autoincrement , respectively, the values ​​are autoincrement from 1 to 5 . But let's assume that when adding the 6th record to the table, the id must be set manually, for example, we need the following line with id = 10 . How to be in this situation? Is it possible to do that? And what will happen next when the id value of autoincrement is on the queue - 10 ?

How to solve such problems?

  • If it comes to mind to set the auto-increment manually, then use it for other purposes. - Sergey
  • @Sergey, such tasks often arise, for example, if you need to merge several databases into one. Another thing is that in the application code, setting this parameter is better not to be abused. However, sunu0074, in my opinion, does not indicate that it is going to perform this operation in the application. - cheops
  • one
    If in two or more bases the same auto-increment id is assigned to different entities, then what to do? In this case, the appointment of new id is inevitable Before or during a merge of a record to a new database, it is assigned another id by the same auto increment on a new base, and not a manual replacement, which only harms. - Sergey
  • @cheops yes, precisely because of this I am afraid that this problem will arise - sanu0074
  • @Sergey but what if these id have many dependencies? Then how to be? - sanu0074

1 answer 1

To set the AUTO_INCREMENT value AUTO_INCREMENT you can use the ALTER TABLE query.

 ALTER TABLE tbl AUTO_INCREMENT = 10; 

The next value will be 10, then the values ​​will go on 11, 12, 13, etc.