如何在MySQL中查找具有特定列名的所有表?

我有2-3个不同的列名,我想在整个数据库中查找并列出所有包含这些列的表。 任何简单的脚本?


要获取数据库YourDatabase中的列columnAColumnB所有表:

SELECT DISTINCT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('columnA','ColumnB')
        AND TABLE_SCHEMA='YourDatabase';

SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%wild%';

更简单地在一行SQL中完成:

SELECT * FROM information_schema.columns WHERE column_name = 'column_name';
链接地址: http://www.djcxy.com/p/30513.html

上一篇: How to find all the tables in MySQL with specific column names in them?

下一篇: One table, two column MYSQL query challenge