我有2-3个不同的列名,我想在整个数据库中查找,并列出所有具有这些列的表。有没有简单的脚本?
当前回答
select distinct table_name
from information_schema.columns
where column_name in ('ColumnA')
and table_schema='YourDatabase';
and table_name in
(
select distinct table_name
from information_schema.columns
where column_name in ('ColumnB')
and table_schema='YourDatabase';
);
这^^将得到表的列na和ColumnB,而不是列na或ColumnB,就像接受的答案
其他回答
select distinct table_name
from information_schema.columns
where column_name in ('ColumnA')
and table_schema='YourDatabase';
and table_name in
(
select distinct table_name
from information_schema.columns
where column_name in ('ColumnB')
and table_schema='YourDatabase';
);
这^^将得到表的列na和ColumnB,而不是列na或ColumnB,就像接受的答案
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%wild%';
SELECT DISTINCT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE 'employee%'
AND TABLE_SCHEMA='YourDatabase'
使用这一行查询。将desired_column_name替换为列名。
SELECT TABLE_NAME FROM information_schema.columns WHERE column_name = 'desired_column_name';
更简单地用一行SQL语句完成:
SELECT * FROM information_schema.columns WHERE column_name = 'column_name';