This query was originally appeared from SQL Authority Blog and I find it really useful when you need to find a column in any tables in a database.
SELECT t.name AS "Table Name", SCHEMA_NAME(schema_id) AS "Schema", c.name AS "Column Name" FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%ColumnName%' ORDER BY 'Schema', 'Column Name';
If you need to find all column names that are in the database, just comment out or delete the highlighted line from the SQL command above.
Further Reading
SQL SERVER – Query to Find Column From All Tables of Database
How to Get Table Definition in SQL Server
How to Find All References to an Object in a SQL Server Database
How to Search for a String in All Tables in a Database
How to Find a String in SQL Server Stored Procedures
Leave a Reply