如何从 MySQL 数据库中搜索列名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36081201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:39:15  来源:igfitidea点击:

How to search a column name from a MySQL database?

mysqlsqldatabasephpmyadmin

提问by Joomler

I am running a huge database with so many tables and tables are having so many columns.

我正在运行一个巨大的数据库,其中有很多表,而且表有很多列。

My DB is MySQL and I have to search for a particular column.

我的数据库是 MySQL,我必须搜索特定的列。

Is there a way available in MySQL to search a column name from all tables in a database?

MySQL 有没有办法从数据库中的所有表中搜索列名?

回答by Ullas

Retrieve it from INFORMATION_SCHEMA COLUMNS Table

INFORMATION_SCHEMA COLUMNS Table

Query

询问

select table_name, column_name 
from information_schema.columns 
where column_name like '%search_keyword%'; -- change search_keyword accordingly

Or if you want to search for exact column name then no need of LIKE.

或者,如果您想搜索确切的列名,则不需要LIKE.

where column_name = 'column_name_to_be_find';

回答by Alok Gupta

Try this:

尝试这个:

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