Reputation: 10302
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.
Upvotes: 1
Views: 12076
Reputation: 15450
For DB2, you will want to use the SYSCAT.COLUMNS
catalog view.
SELECT *
FROM SYSCAT.COLUMNS
WHERE COLNAME LIKE '%COL_FAX_ID%'
Upvotes: 0
Reputation: 24144
For oracle:
SELECT table_name,column_name from all_tab_columns
where column_name like '%COL_FAX_ID%'
Upvotes: 0
Reputation:
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%'
Upvotes: 2
Reputation: 1035
select distinct table_name from all_tab_columns where column_name like %'COL_FAX_ID%'
Upvotes: 0
Reputation: 17538
For Oracle, you could try:
SELECT owner,
table_name,
column_name
FROM all_tab_cols
WHERE column_name LIKE '%COL_FAX_ID%'
ORDER BY owner,
table_name;
For a full list of the Oracle data dictionary views etc. see here.
Hope it helps...
Upvotes: 6
Reputation: 10490
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
Upvotes: 0