Home >Database >Mysql Tutorial >What should I do if the added data ID does not follow immediately after mysql auto-increment and deletion?

What should I do if the added data ID does not follow immediately after mysql auto-increment and deletion?

coldplay.xixi
coldplay.xixiOriginal
2020-10-15 11:47:073798browse

After mysql auto-increment and deletion, the solution to adding data id will not follow: first open the Mysql code editor; then after deleting 4, execute the relevant sql statement, the code is [ALTER TABLE table_name AUTO_INCREMENT = 1 ;].

What should I do if the added data ID does not follow immediately after mysql auto-increment and deletion?

After mysql is added and deleted, the added data id will not be followed immediately. Solution:

Problem: mysql After deleting the auto-incremented id data from the table, the ids will not follow when adding data again.

For example:

Auto-increment id

1
2
3
4

Now delete 4, it becomes

1
2
3

At this time, if you add a piece of data, it will become

1
2
3
5

The above 5 is not the result we want, 4 is the ideal id,

The solution is to execute the following sql statement after deleting 4:

ALTER TABLE table_name AUTO_INCREMENT = 1;

Related free learning: mysql database(database)

The above is the detailed content of What should I do if the added data ID does not follow immediately after mysql auto-increment and deletion?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn