4
1

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.

Oracleの各テーブルのカラム数を調べたい場合のSQL

Posted at

パフォーマンス調査で、テーブルのカラムの最大数を調べたいケースが出たので、SQLを作ってみた。

all_tab_column_count.sql
SELECT TABLE_NAME ,COUNT(*) as COUNT
FROM ALL_TAB_COLUMNS  
GROUP BY TABLE_NAME
ORDER BY COUNT DESC;

今回の場合はALL_TAB_COLUMNSに存在するTABLE_NAMEカラムでグルーピングした項目の数をCOUNTした上で降順にしている。

ALL_TAB_COLUMNSについて

ALL_TAB_COLUMNS は以下のような情報を持つテーブルです。

DBA_TAB_COLUMNSは、データベース内すべての表、ビューおよびクラスタの列を示します。
USER_TAB_COLUMNSは、現行のユーザーが所有する表、ビューおよびクラスタの列を示します。このビューは、OWNER列を表示しません。

詳細については以下のリンク参照。
https://docs.oracle.com/cd/E16338_01/server.112/b56311/statviews_2103.htm

あんまり使うことはないかもしれないが、備忘も兼ねて記載。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?