4
5

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 TIPS

Last updated at Posted at 2015-02-05

###ローカルでの接続
db2cmd
connect to XXX user aaaa using xxxx

###接続解除
db2 connect reset

###SQL実行
db2 -tvcmf ./update.sql

test.sql
select * from aaa fetch first 100 rows only with ur;

###dual
sysibm.sysdummy1

###日付比較
・DATE('2013-01-01') <= DATE(DATE型)
・CURRENT DATE BETWEEN A AND B
・TIMESTAMP(------)

##DB2の初期設定
db2 get dbm cfg | grep SVCENAME
db2c_xxxx
grep db2c_xxxx /etc/services

####ノード一覧を表示
LIST NODE DIRECTORY
LIST DB DIRECTORY

###容量が一杯のときは
REORG

#インポート

 IMPORT FROM employee.ixf OF IXF CREATE INTO employee COMMITCOUNT 10000 MESSAGES [LOGファイル] 
INSERT_UPDATE INTO 表名 

#エクスポート

EXPORT TO employee.ixf OF IXF
   LOBS TO ./test_LOBFILE lob
   MODIFIED BY LOBSINFILE CODEPAGE=1208
   SELECT * FROM AAAA WHERE AAA WITH UR;

##スキーマ単位のエクスポート
カレントディレクトリに出力される

export DB2CODEPAGE=1208
db2move db名 EXPORT -sn スキーマ名

#ペンディング
ペンディング状態の回復
reorg table tab1

select tabschema,tabname,reorg_pendingi num_reorg_rec_alters from sysibmadm.admintabinfo where reorg_pending = 'Y'
select tabschema,tabname,X.* from syscat.tables X where status <> 'N'
'C' 表のペンディング
'X' VIEWのペンディング

#VIEWのペンディング

select X.* from syscat.views X where status <> 'N'

select X.* from syscat.views X where  valid <> 'Y'

VIEWの場合は、再作成すること

##ID列があるテーブル
select * from syscat.columns where identity = 'Y'

#統計情報 RUNSTATS
RUNSTATS ON TABLE AAA.AAA AND DETAILED INDEXES ALL

#DDL table

db2lock -d xxx_ken -e -z xxxx001 -i xxdbinst -w xxxx -t TABLENAME
DDL view

select text from syscat.views
where viewname = 'TABLE_NAME'

#マスタレコードを結合して1件のみと結合したい
rownumber over partition 抽出
where rownumber = 1で絞る

#UDF作成
マニアックなプログラミング備忘録

#SQLプロシージャー
[SQLプロシージャー]
(http://www-6.ibm.com/jp/software/data/db2univ/data/sqlprocedure.pdf)

インラインSQL
BEGIN ATOMIC
DECLARE A SAMLLINT;
END

IBM [DB2 LUW] 大量の行を削除する時のログ量を減らす方法 - Japan

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?