What Was I Thinking?

Follies & Foils of .NET Development
posts - 95 , comments - 352 , trackbacks - 0

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;

Print | posted on Thursday, April 26, 2012 10:59 AM | Filed Under [ SQL ]

Feedback

Gravatar

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

You can also:

select TABLE_NAME
from
information_schema.columns
where column_name like '%fname%'
11/27/2012 5:04 PM | Justin R
Gravatar

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

My acquaintance accredit your site and I appreciate it, it acceptable and altered with beginning online autograph .
12/29/2012 11:32 AM | manandwomanfashion.com
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: