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 1 year has passed since last update.

【DB2】システムカタログから特定テーブルのカラム名を取得する

Posted at

はじめに

アプリケーションサーバー側(Java)で、次の処理を行う必要が生じた。

データベースサーバ(DB2)の特定のスキーマ.特定のテーブルに登録されている全カラム名を取得したい

DB2を使った開発現場からはすでに離れてしまったのと、当時の走り書きと曖昧な記憶しか残っていないため、参考程度に備忘録を残しておく。
(もしかすると、SQLも細かいところで間違っているかもしれない)

どうするか

スキーマ名とテーブル名を抽出条件として、SYSCAT.COLUMNSからカラム名の情報を取り出す。

SELECT COLNAME FROM SYSCAT.COLUMNS WHERE TABSCHEMA = 'HOGESCHEMA' AND TABNAME = 'TABLENAME'

アプリケーションサーバー側で上記のSQLを実行、検索結果のレコードを1件ずつ取り出していく。

参考

SYSCAT.COLUMNS カタログ・ビュー

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?