PostgresSQL 操作方法

  • データベース起動
$ postgres -D /usr/local/var/postgres
  • データベースの作り方
$ createdb [dbname]
  • データベースへと接続
$ psql -U [username] [dbname]
  • テーブルの作成(確認)
 # create table [tbname](id integer,price integer);
 # \d [tbname]
  • テーブルの削除
 # drop table [tbname];
  • テーブルカラムのタイプの変更
 # alter table [tbname] alter column [clname] type [char(20)];
  • テーブルカラムの追加
 # alter table [tbname] add type [int];
  • テーブル権限の設定
 # grant SELECT, UPDATE, DELETE, INSERT on [tbname] to [username];
  • レコード入力と確認方法
 # insert into [tbname] values(99,999);
 # select * from [tbname]
  • レコードアップデート
 # update [tbname] set [colname]=[value] where [colname] = [value];
  • レコードクリア
 # delete from [tbname];

参考資料