Objective: Search for strings in several specified columns in various tables in all databases on a server.
First, I need to find the strings I will be searching for. I think this is a two part process.
Part 1 - Write a query that will return the ServerName, DatabaseName, TableName, and ColumnName of a specifiedtable and column. I don't know how to get the DatabaseName from the following query. Plus, I want to ensure thisquery is searchingALL databases on the server.
select @@SERVERNAME, o.name as TableName, c.name as ColumnName from sys.columns as c inner join sys.objects as o on c.object_id = o.object_id where (o.name = 'Table1' and c.name = 'Column1') or (o.name = 'Table2' and c.name = 'Column2') order by o.name,c.column_id
Part 2 - All the databases returned in the above query will contain a table called Dictionary and columns calledMetaData, TableName, & ColumnName. I want to query all the Dictionary tables in the Databases returned in theabove query. I need to return the MetaData column values where the TableName and ColumnName match. Something like this:
Secondly, once I have all the MetaData values I'll need to search the following table fields in all the databases in the query above to see if they contain the MetaData. For example, WHERE dba.GlobalFilters.CalcExpr LIKE '%string1%'.
I hope this makes sense. Our object model contains a lot of meta data and I need to find all the affected meta data.
Ryan