Sql Server: Get all tables containing column with a specified name

A little helper query I came accross, very useful if you want to find all the tables that contain a specific column:

SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%ColumnName%'

 

What it basically does is that it will do a join on sys.columns and sys.tables to get all tables that contains that particular column in your Sql Server instance.

Advertisements
Sql Server: Get all tables containing column with a specified name

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s