Thursday, December 23, 2010

Find Column in Database - SQL Server

Use the following query to find column in your database. Change “yourdbname” and “%ColumnNameToSearch%” column name accordingly.

Use yourdbname
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
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 '%ColumnNameToSearch%'
ORDER BY schema_name, table_name;

Thanks to Pinaldave.

No comments:

Post a Comment

Feel free to give constructive feedback or let me know if it was helpful.