0
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 3 years have passed since last update.

よく使うSQLコマンド集

Posted at

##データを更新
UPDATE tbl_nm SET field_nm1=xxx, field_nm2=yyy WHERE field_nm3=zzz;
##データを追加(全て)
INSERT INTO tbl_nm (val1, val2, ...);
##データを追加(指定の項目)
INSERT INTO tbl_nm (field1,field2, ...) VALUES (val1, val2, ...);
##テーブル定義変更
ALTER TABLE tbl_nm ALTER COLUMN field_nm TYPE データ型;
##シーケンス
###シーケンスを作成
CREATE sequence シーケンス名
###シーケンスの値を設定、初期化
SELECT setval('シーケンス名', val);
###任意のテーブルのシーケンス最大値+1にシーケンスを設定
SELECT setval('シーケンス名', (SELECT MAX(id)+1 FROM tbl_name));
###シーケンスの値を確認
SELECT last_value FROM seaquence;
###シーケンス削除
DROP sequence シーケンス名

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