Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all tables containing a given column name

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.

like image 751
smokinguns Avatar asked Feb 08 '10 21:02

smokinguns


People also ask

How can I find all the tables in MySQL with specific column names in them?

SELECT DISTINCT TABLE_NAME FROM information_schema. columns WHERE TABLE_SCHEMA = 'your_db_name' AND TABLE_NAME NOT IN (SELECT DISTINCT TABLE_NAME FROM information_schema. columns WHERE column_name = 'column_name' AND TABLE_SCHEMA = 'your_db_name');

How do I list the column names in a table in SQL?

USE db_name; DESCRIBE table_name; it'll give you column names with the type.

How can I find a particular column name within all tables in hive?

Here's the query you can use on the metastore: select TBL_NAME, COLUMN_NAME, TYPE_NAME from TBLS left join COLUMNS_V2 on CD_ID = TBL_ID where COLUMN_NAME like 'column'; where 'column' is the column name you're looking for.


1 Answers

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';
like image 50
Ed Massey Avatar answered Nov 04 '22 01:11

Ed Massey