There are several ways to look for a column in your SQL Server database.
Alternative 1: INFORMATION_SCHEMA.COLUMNS (T-SQL)
DECLARE @colName NVARCHAR(30) SET @colName = 'name' SELECT TABLE_CATALOG AS 'Database', TABLE_SCHEMA AS 'Schema', TABLE_NAME AS 'Table', COLUMN_NAME AS 'Column' FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%' + @colName + '%'
Alternative 2: sys.columns (T-SQL)
SELECT sys.tables.name AS 'Table', sys.columns.name AS 'Column' FROM sys.columns INNER JOIN sys.tables ON sys.tables.object_id = sys.columns.object_id WHERE sys.columns.name LIKE '%' + @colName + '%'
Alternative 3: Object Search (SSMS)
In SQL Server 2000, there was an “Object Search” tool in Query Analyzer to search for objects.
To get to this tool in SQL Server 2000, either
– Go to Tools > Object Search, or
– Press F4
Unfortunately this was removed in SQL Server 2005.
But back again in SQL Server 2008:
– Go to View > Object Explorer Details
– Type object name in the Search bar
– Press Enter to Search
Yay!
How to Search for Columns in SQL Server,Filed under:
DBA Toolbox / T-SQL Scripts, T-SQL Tips and Tricks
Thanks Belle. As you know, option 1 works for Sqlserver 2000 whereas option 2 requires a later version. Unfortunately Sqlserver 2008’s object explorer search does not return any results when I enter a column name! I tried it on 2008, 2005 and 2000 database servers and it failed on all.
[…] How to Search for Columns in SQL Server … […]