2

I'm using SQL Server 2012 and was wondering if there is a way to find all tables in a given database that contain a certain column?

Shawn
  • 2,356
  • 6
  • 48
  • 82
Drew
  • 2,583
  • 5
  • 36
  • 54

2 Answers2

3
select
    quotename(S.name) + '.' + quotename(T.name) as [Table]
from sys.columns C
    join sys.tables T on T.object_id = C.object_id
    join sys.schemas S on S.schema_id = T.schema_id
where C.name = 'ColumnName'
order by 1
i-one
  • 5,050
  • 1
  • 28
  • 40
2

I think the easiest way is to use the INFORMATION_SCHEMA.COLUMNS table:

select c.SCHEMA_NAME, c.TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS c
where c.COLUMN_NAME = @YOURCOLUMNNAME;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786