7

In SQL Server how do you query a database to bring back all the tables that have a field of a specific name?

3 Answers 3

7

The following query will bring back a unique list of tables where Column_Name is equal to the column you are looking for:

SELECT Table_Name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE Column_Name = 'Desired_Column_Name'
GROUP BY Table_Name
0
SELECT Table_Name
FROM Information_Schema.Columns
WHERE Column_Name = 'YourFieldName'
0

I'm old-school:

SELECT DISTINCT object_name(id)
FROM syscolumns
WHERE name = 'FIELDNAME'

Not the answer you're looking for? Browse other questions tagged or ask your own question.