SQL query for database schema

In SQL Server, how do you query the database to return all tables that have a field with a specific name?

+5
source share
3 answers

The following query returns a unique list of tables where Column_Nameis 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
+6
source
SELECT Table_Name
FROM Information_Schema.Columns
WHERE Column_Name = 'YourFieldName'
0
source

I am an old school:

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

All Articles