Many times we come across a requirement of finding names of all tables which contain specific columns. We can get the answer by using the below query:
SELECT COL.name AS ColumnName, TAB.name AS TableName
FROM sys.columns COL
JOIN sys.tables TAB ON COL.object_id = TAB.object_id
WHERE COL.name LIKE '%ColumnNameToSearch%'
For example ,if we want to find names of table containing column by the name employee. The corresponding query will be as below:
SELECT COL.name AS ColumnName, TAB.name AS TableName
FROM sys.columns COL
JOIN sys.tables TAB ON COL.object_id = TAB.object_id
WHERE COL.name LIKE '%employee%'
0 Comment(s)