I have 2-3 different column names that I want to look up in the entire DB and list out all tables which have those columns. Any easy script?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
In version that do not have
information_schema
(older versions, or some ndb's) you can dump the table structure and search the column manually.Now search the column name in
some_file.sql
using your preferred text editor, or use some nifty awk scripts.And a simple sed script to find the column, just replace COLUMN_NAME with your's:
You can pipe the dump directly in sed but that's trivial.
Use this one line query, replace desired_column_name by your column name.
More simply done in one line of SQL:
For those searching for the inverse of this, i.e. looking for tables that do not contain a certain column name, here is the query...
This came in really handy when we began to slowly implement use of InnoDB's special
ai_col
column and needed to figure out which of our 200 tables had yet to be upgraded.To get all tables with columns
columnA
orColumnB
in the databaseYourDatabase
: