1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Auto incrementでレコード消したら歯抜きになるのを直す

Posted at

#問題
MysqlでAuto incrementをオプションにしてるidなどのカラムで,
途中でレコードを消すと,そこが抜けたまま次のidが入れられてしまう
それをかっこ悪いので直したい

#手順
1.次の連番番号を決める
ALTER TABLE テーブル名
AUTO_INCREMENT=次に始まる番号;

2.歯抜きをきれいにする
SET @i := 0;
UPDATE テーブル名 SET id = (@i := @i +1) ;

それだけです

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?