mysql id starts from 1 and increases automatically to solve the problem of discontinuous idAs a person with obsessive-compulsive disorder, I cannot tolerate the problem of discontinuous ids after deleting some rows in the table. At first, I used TRUNCATE TABLE tablename To achieve the self-increment of id from the beginning, but this command will also clear the entire table, which is really a pitfall. Later I found the correct approach:alter table tablename auto_increment = 1; This command will not change the content and order of the existing table. At the same time, the id of the newly inserted row will first use the deleted id to perfectly fill the vacant id. MySQL auto-increment id jump solution (without deleting data)Problem description:I'm importing a large amount of data from Excel to MySQL. The auto-increment ids are not incremented in sequence, and many are skipped in the middle. I don't want to re-import them because of the huge amount. Solution:Sort by id or time from small to large ==> Get the row number ==> Replace the original id with the row number SQL statement:update tab as t1 join (select id,(@rowno:=@rowno+1) as rowno from tab a,(select (@rowno:=0)) b order by a.id) as t2 SET t1.id=t2.rowno WHERE t1.id=t2.id; The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Several techniques for playing sounds with CSS
>>: Explore how an LED can get you started with the Linux kernel
Table of contents 1. Comments on MySQL primary ke...
To beautify the table, you can set different bord...
When configuring the interface domain name, each ...
Table of contents 1. Basic overview of the proces...
Preface: I used the official nginx proxy_cache as...
What I want to share today is to use native JS to...
Table of contents Error demonstration By computed...
Table of contents Introduction Uses of closures C...
Table of contents 1. The difference between trans...
In an unordered list ul>li, the symbol of an u...
Table of contents 1. Configure Linux hostname Con...
1) Enter the folder path where the jdk file is st...
Table of contents Installation package download I...
<br />According to statistics, the average s...
This article mainly introduces the effect of div ...