LoginSignup
36
24

More than 5 years have passed since last update.

[SQL]1行で主キーを変更する

Posted at

主キーを変更したい

新規実装に当たって既存の主キーを変える必要が出てきた。
が、調べてもなかなか変える為の構文が出てこない。
解決法はシンプルだったので備忘録として残しておく。

構文

SQL
ALTER TABLE table_name DROP PRIMARY KEY, ADD PRIMARY KEY (id);

やっていることはいたってシンプルで、主キーを削除して主キーを追加しているだけ。

36
24
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
36
24