mysqlでデータを削除した後、データを追加し、id値は依然として削除の位置から増加し、問題は詳しく説明します.
2442 ワード
+----+--------------+-----+----------------------+----------+
| id | name | age | email | isActive |
+----+--------------+-----+----------------------+----------+
| 1 | | 32 | [email protected] | 1 |
| 2 | | 32 | [email protected] | 1 |
| 3 | | 32 | [email protected] | 1 |
| 4 | | 32 | [email protected] | 1 |
| 5 | | 32 | [email protected] | 0 |
+----+--------------+-----+----------------------+----------+
上記のmysqlテーブルにあるデータが重複している場合は、再追加データを削除する必要があります.
delete from index_author where id=2;
delete from index_author where id=3;
削除後のmysqlの内容は
+----+--------------+-----+----------------------+----------+
| id | name | age | email | isActive |
+----+--------------+-----+----------------------+----------+
| 1 | | 32 | [email protected] | 1 |
| 3 | | 32 | [email protected] | 1 |
| 4 | | 32 | [email protected] | 1 |
| 5 | | 32 | [email protected] | 0 |
+----+--------------+-----+----------------------+----------+
** id , , , :**
+----+--------------+-----+----------------------+----------+
| id | name | age | email | isActive |
+----+--------------+-----+----------------------+----------+
| 1 | | 32 | [email protected] | 1 |
| 6 | | 32 | [email protected] | 1 |
| 7 | | 32 | [email protected] | 0 |
+----+--------------+-----+----------------------+----------+
id値は6から増加することが分かった.
どうやってこの問題を解決しますか?
:
alter tableテーブル名AUTO_INCREMENT=n;
n , 。
:
alter table index_author AUTO_INCREMENT=2;
, :
+----+--------------+-----+----------------------+----------+
| id | name | age | email | isActive |
+----+--------------+-----+----------------------+----------+
| 1 | | 32 | [email protected] | 1 |
| 2 | | 32 | [email protected] | 1 |
| 3 | | 32 | [email protected] | 0 |
+-----+--------------+-----+----------------------+----------+