71
64

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.

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;
71
64
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
71
64

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?