29
30

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.

DB2で個人的によく使うコマンド

Posted at

##DBの作成
db2 => CREATE DB test_db

##DBの削除
db2 => DROP DB test_db

##DBの一覧表示

db2 => LIST DATABASE DIRECTORY

または(上記と結果は同じ)

db2 => LIST DB DIRECTORY

##DBへの接続

db2 => CONNECT TO test_table

##TABLEの作成
db2 => CREATE TABLE test_table (
id INTEGER NOT NULL,
name VARCHAR(40) NOT NULL,
address VARCHAR(60),
tel VARCHAR(20),
created_at timestamp,
deleted_at timestamp,
updated_at timestamp,
PRIMARY KEY (id)
)

##TABLEの削除
db2 => DROP TABLE test_table

##既存TABLE定義の変更
// カラムの追加
db2 => ALTER TABLE test_table ADD COLUMN test_column VARCHAR(256)

// カラムの削除
db2 => ALTER TABLE test_table DROP COLUMN test_column	

// 属性の付与
db2 => ALTER TABLE test_table ALTER test_column SET NOT NULL

// 属性の削除
db2 => ALTER TABLE test_table ALTER test_column DROP NOT NULL  

##既存TABLE定義の確認
db2 => DESCRIBE TABLE test_table

##終わりに
毎度調べるのがめんどくさいので、個人的によく使うものをまとめました、他にもコマンドはあるので随時追加していきたいと思います!
オプションなども追加したいですね!

##参考
http://db2watch.com/wiki/index.php?title=%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8

29
30
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
29
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?