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
Release: 2020-10-15 11:47:40
Original
3763 people have browsed it

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
Copy after login

Now delete 4, it becomes

1
2
3
Copy after login

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

1
2
3
5
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template