1
0

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 1 year has passed since last update.

SQL – テーブルのカラムを後から AUTO_INCREMENT に変更するクエリ

Posted at

AUTO_INCREMENT と PRIMARY の両方を設定する必要があるようだ

ALTER TABLE [table_name] MODIFY [column_name] INT NOT NULL PRIMARY KEY AUTO_INCREMENT;

検証例

CREATE TABLE articles (
  id INT
);

INSERT INTO articles (id) VALUES (100);

ALTER TABLE articles MODIFY id INT NOT NULL PRIMARY KEY AUTO_INCREMENT;  

INSERT INTO articles () VALUES ();
INSERT INTO articles () VALUES ();
INSERT INTO articles () VALUES ();

ID は今までの最大の値から振られるようだ

image

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?