How to find all tables / views with a column name that matches a specific pattern
1 answer
dbc.ColumnsV stores information about columns:
SELECT DatabaseName, TableName, ColumnName
FROM dbc.ColumnsV
WHERE ColumnName LIKE '%abcd%'
;
This can return stored routines or macros as well, so you'd better join dbc.TablesV:
SELECT t.DatabaseName, t.TableName, t.TableKind, ColumnName
FROM dbc.TablesV AS t JOIN dbc.ColumnsV AS c
ON t.DatabaseName = c.DatabaseName
AND t.TableName = c.TableName
WHERE ColumnName LIKE '%abcd%'
AND TableKind in ('T','V')
;
+9
source to share