How do I list all the tables in a database that contain a column with a given name?
Asked
Active
Viewed 5.8k times
4 Answers
24
Try this:
select distinct object_name(id)
from syscolumns
where name = 'my_column_name'
order by object_name(id)
or this way:
select distinct so.name
from syscolumns sc
, sysobjects so
where sc.id = so.id
and sc.name = 'my_column_name'
order by so.name
is that what you've been looking for?

B0rG
- 1,215
- 12
- 13
4
You can also use sp_columns stored procedure.
sp_columns @column_name = '%column_name%'
More info here: SyBooks Online (Getting Help On Database Objects)

Miguel
- 1,575
- 1
- 27
- 31
3
The below query can be used to get column_name with table_name as well.
This will help the user identify the table to which the column_name belongs.
select distinct tbl_col.name as Field_name,tbl_object.name as Table_name
from syscolumns tbl_col
, sysobjects tbl_object
where tbl_col.id = tbl_object.id
order by tbl_object.name