LoginSignup
0
0

More than 3 years have passed since last update.

特定のカラム名を持つテーブルを探す on MySQL

Posted at

株式会社オズビジョンのユッコ (@terra_yucco) です。
今日は何番煎じかわかりませんが、件名の通り。

SQL

select table_name, column_name
  from information_schema.columns
 where column_name = '<column name>' and table_schema = '<database name>';

カラム名が特定できない場合

例えば今回は IP アドレスを見たかったのですが ip, src_ip, ip_addr などまあ色々入り混じっています。なので like を使って関連も取得しました。
この場合最終的には出力結果の目検が必要 (description とかが引っかかる) ですが、幅を広げて確認できます。

select table_name, column_name
  from information_schema.columns
 where column_name like '%<column name>%' and table_schema = '<database name>';
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