MySQL will not be quick fix for the continuous sequential ID

MySQL data in the table discontinuity could happen for several reasons:

  1. insert statements, whether successful, it will increase AUTO_INCREMENT value.

  2. Conducted delete related operations.

  3. rollback related.

But no matter what the situation is due to lead, leadership there is this need, we can only follow suit!

Conventions:

  • Source table: source

  • Target table: destination

Pseudo-SQL statement:

SQL insert into destination (“字段") select 字段 from source;

This simply complete copy from one table to another table. And we can use syntactic sugar, will grow from the primary key and other related fields ignored. Allowing the system to help us achieve insertion of continuity.

After completion of the introduction, using count(*)the select 自增长主键 from 表 order by 主键 desc limit 1combined data in the table to determine whether continuous.

At last:

  • Since growth in the value of the checklist whether the last message id + 1, or manually change it.

  • The target table with the source table name swap. mission completed!

the above.

Guess you like

Origin blog.csdn.net/My_CandyS/article/details/92073886