如何在 MySQL 中找到包含特定列名的所有表?

2021-11-20 00:00:00 mysql information-schema

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

I have 2-3 different column names that I want to look up in the entire database and list out all tables which have those columns. Is there any easy script?

推荐答案

获取YourDatabase数据库中包含columnAColumnB列的所有表>:

To get all tables with columns columnA or ColumnB in the database YourDatabase:

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

相关文章