LoginSignup
68
62

More than 3 years have passed since last update.

Postgresでのカラム追加、削除、型変え

Posted at

Postgresでのカラム追加、削除、型変えのコマンドです。

テーブルにカラムを追加

ALTER TABLE テーブル名 ADD COLUMN カラム名 データ型;
(例) ALTER TABLE t_user ADD COLUMN user_type int2; 

テーブルのカラムを削除

カラムのデータが消えてしまうので注意しましょう

ALTER TABLE テーブル名 DROP COLUMN カラム名;
(例) ALTER TABLE t_user DROP COLUMN user_type; 

カラムのデータ型を変更

ALTER TABLE テーブル名 ALTER COLUMN カラム名 TYPE データ型
(例) ALTER TABLE t_user ALTER COLUMN user_type TYPE VARCHAR;
68
62
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
68
62