What Was I Thinking?

Follies & Foils of .NET Development
posts - 86 , comments - 254 , trackbacks - 0

April 2012 Entries

Query SQL Server’s schema to find all tables containing a column named ‘x’

The following query will find all tables in my catalog with a column name like ‘city’

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 '%City%'
ORDER BY schema_name, table_name;

Posted On Thursday, April 26, 2012 10:59 AM | Comments (2) | Filed Under [ SQL ]

Powered by: