MySQL搜索列名

MySQL搜索列名

 

有时候需要看到底是那个表中有某个你需要列,尤其是你操作别人设计好的数据表的时候,比如你要搜索数据库DB_xxx中那个表有xxx这个列,那么名就如下:

SELECT DISTINCT TABLE_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('xxx')
        AND TABLE_SCHEMA='DB_xxx;

+—————-+
| TABLE_NAME     |
+—————-+
| table_xxx |
+—————

如果你想搜索列,则改动COLUMN_NAME IN ('xxx'),变成

COLUMN_NAME IN ('xxx',‘yyy')假设你另外要找列明是yyy,整个命令变成:

SELECT DISTINCT TABLE_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('xxx','yyy')
        AND TABLE_SCHEMA='DB_xxx;

+—————-+
| TABLE_NAME     |
+—————-+
| table_xxx |
| table_yyy    |

 

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:
This entry was posted in MySql. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*