List all tables containing a given column name

北战南征 提交于 2020-01-22 13:36:05

问题


How do a I list all tables containing a given column name? I'm using Mysql version 4.1.13-nt-log. I know versions less than 5 dont have an information_scheme DB.


回答1:


Find all tables and columns where column names are like the search term:

SELECT DISTINCT TABLE_NAME, COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%partial_column_name%'
    AND TABLE_SCHEMA='YourDatabase';



回答2:


try this:

mysqldump -u root -p –all-databases –single-transaction > all.sql

and then do the searching the old-school way in a text editor with find


also found this... looks promising, but I'm not sure how ambitious you are

http://mike.kruckenberg.com/presentations/Creating_INFORMATION_SCHEMA.pdf




回答3:


Much more easily

SELECT DISTINCT TABLE_NAME FROM your_schema.columns WHERE column_name = 'your_column_name';



回答4:


select table_name,column_name,data_type,data_length 
from user_tab_columns 
where column_name LIKE 'WHATEVER_U_WANT'
;


来源:https://stackoverflow.com/questions/2224860/list-all-tables-containing-a-given-column-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!