3
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 5 years have passed since last update.

PRESTOで必要なテーブルをワイルドカード指定で検索する方法

3
Last updated at Posted at 2019-08-04

テーブルを名称から検索する

SELECT  
  CONCAT(table_schema, '.', table_name) AS DB_TABLE_NAME
FROM
(
  SELECT 
    DISTINCT table_schema, table_name
  FROM
    information_schema.tables
  WHERE
    table_schema LIKE '%scheme%'  -- ここに検索対象のschemeを指定する
  AND
    table_name LIKE '%table%'  -- ここに検索したいテーブル名称を指定する
)
;

出力結果例

DB_TABLE_NAME
scheme.table1
scheme.table2

カラム名が存在するテーブルをすべて検索する

SELECT 
  CONCAT(table_schema, '.', table_name) AS DB_TABLE_NAME
  , column_name
  , comment
FROM
(
  SELECT
    DISTINCT table_schema, table_name, column_name, comment
  FROM 
    information_schema.columns
  WHERE
    table_schema LIKE '%scheme%'  -- ここに検索対象のschemeを指定する
  AND
    column_name LIKE '%column%'  -- ここに検索対象のcolumnを指定する
)
; 

出力結果例

DB_TABLE_NAME column_name comment
scheme.table1  X_column hello
scheme.table2  column_name hi!
scheme.table3  column_id good morning
3
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
3
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?