Have you ever known then name of a column but couldn't remember what table it was in. Or wanted to create a join and need to find matching column names? Well this snippet of code will return the name of a table which has a column name you specify:
SELECT t.NAME AS table_name
,SCHEMA_NAME(schema_id) AS schema_name
,c.NAME AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.NAME LIKE
'%<column_name>%'
ORDER BY schema_name
,table_name;
[This piece of code is ideal for a Snippet]
Comments
Post a Comment