如何在 mysql 数据库中搜索特定列名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12009961/
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
How do i search a mysql database for a specific column name
提问by Ledgemonkey
I'm trying to find if my database has a column named sort_method
. I have had a look around the forums but don't seem to be able to find the right answer. My database has over 300 tables so manually looking for it is not an option.
我正在尝试查找我的数据库是否有名为sort_method
. 我已经环顾了论坛,但似乎无法找到正确的答案。我的数据库有 300 多个表,因此手动查找它不是一种选择。
I'm using phpMyAdmin - SQL query
我正在使用 phpMyAdmin - SQL 查询
回答by Andy
SELECT table_name,table_schema
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name='sort_method'
回答by Mike Christensen
You can query the INFORMATION_SCHEMA.COLUMNS
system table:
可以查询INFORMATION_SCHEMA.COLUMNS
系统表:
SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'sort_method'
More Info at: http://dev.mysql.com/doc/refman/5.0/en/columns-table.html
更多信息:http: //dev.mysql.com/doc/refman/5.0/en/columns-table.html
回答by John Woo
Try
尝试
SELECT DISTINCT TABLE_NAME
? ? FROM INFORMATION_SCHEMA.COLUMNS
? ? WHERE COLUMN_NAME = 'columnName'
? ? ? ? AND TABLE_SCHEMA='YourDatabase';