SQL query for a database scheme
-
08-06-2019 - |
Question
In SQL Server how do you query a database to bring back all the tables that have a field of a specific name?
Solution
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
OTHER TIPS
SELECT Table_Name
FROM Information_Schema.Columns
WHERE Column_Name = 'YourFieldName'
I'm old-school:
SELECT DISTINCT object_name(id)
FROM syscolumns
WHERE name = 'FIELDNAME'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow