LoginSignup
2
1

More than 5 years have passed since last update.

【Mysql】データベースのidを連番に変更する

Posted at

テストの投稿があまりにも増えすぎてIDが半端なくスカスカ、なにがなんだかわからなくなってました。。。。
現状入っているデータを連番に出来ないと思って調べると以下のコードでIDを連番に変更できた。

SET @i := 0 ;
UPDATE `column` SET id = (@i := @i +1) ;

SET @i := 0 ;
UPDATE `カラム名` SET id = (@i := @i +1) ;

注意点として、変更するテーブルがリレーションしていると、関連テーブルは変更されないと思うので要注意です。

2
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
2
1