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,307
  • 4
  • 47
  • 79
Drew
  • 2,493
  • 5
  • 35
  • 52

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
  • 4,890
  • 1
  • 25
  • 39
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,198,228
  • 53
  • 572
  • 709