3/21/2018 - 1:25 PM

SQL Lookup Column Name

This script allows you to find the name of Tables that contain a certain column name, useful when you know the field, but not where the data is coming from.

Also useful for checking for foreign keys, if naming convention is good.

SELECT AS SchemaName, AS TableName, AS ColName
FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
	JOIN sys.schemas s ON s.schema_id = t.schema_id
WHERE LIKE '%weight%'
ORDER BY SchemaName, TableName, ColName
    table_name, column_name, data_type
where table_schema = 'SCHEMANAME'
order by table_name, column_name