Can I write an sql query that can find the names of all tables in a database that have column name like %COL_FAX_ID%. If so, how?
Database used is oracle or db2.
Can I write an sql query that can find the names of all tables in a database that have column name like %COL_FAX_ID%. If so, how?
Database used is oracle or db2.
I don't have an oracle install lying around to test this with but you should be able to do something like:
SELECT TABLE_NAME
FROM ALL_TAB_COLUMNS
WHERE COLUMN_NAME LIKE '%COL_FAX_ID%'
Dublicate of possible How to find all the tables in MySQL with specific column names in them?
Answer:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB')
AND TABLE_SCHEMA='YourDatabase';
Edit: Sorry I Miss saw the sql for beeing mysql tag... But this may work aswell? Dunno. Gl & Hf
select distinct table_name from all_tab_columns where column_name like %'COL_FAX_ID%'
For oracle:
SELECT table_name,column_name from all_tab_columns
where column_name like '%COL_FAX_ID%'
For DB2, you will want to use the SYSCAT.COLUMNS
catalog view.
SELECT *
FROM SYSCAT.COLUMNS
WHERE COLNAME LIKE '%COL_FAX_ID%'