Thursday, May 29, 2014

How to search a column name within all tables of a database?

Here is how we can get table name and column which you are looking for,

SELECT table_name,column_name FROM information_schema.columns
WHERE column_name like '%engine%'
-- OR ---
SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%engine%'



Sample OUTPUT for one of the query,


ColName    TableName
EngineType    DSS_Setup