开发者

MySQL, search a database and tell what tables contain two specific columns?

I have a database with well over 90 tables and I am trying to figure which, if any, of them have the same two specific columns. The code I am looking for would be something like this:

SHOW TABLES IN `database` 
      WHERE co开发者_StackOverflow中文版lumn = 'columnA' 
        AND column = 'columnB';`

Is this even possible?


This will give you all tables having either of the two columns, which you can browse through to find what you need.

  select *
    from information_schema.columns
   where column_name in ('columnA', 'columnB')
order by table_name, column_Name


SELECT TABLE_SCHEMA AS `schema`, TABLE_NAME AS `table`, COLUMN_NAME AS `column` 
FROM `information_schema`.`COLUMNS` 
WHERE COLUMN_NAME IN('column1','column2')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜