In SQL Server Management Studio can I search for assets across multiple databases?

StackOverflow https://stackoverflow.com/questions/149054

  •  02-07-2019
  •  | 
  •  

Question

My everyday IDE is Eclipse which has a wonderful Open Resource feature (CTRL+SHIFT+R or Navigate > Open Resource) which allows the user to search for files/resources across multiple projects.

I can't find a similar feature in SQL Server Management Studio, is there one?

Was it helpful?

Solution

You can search for objects in a sql database using the Information Schema Views http://msdn.microsoft.com/en-us/library/ms186778.aspx There's one for tables, columns, functions, sprocs, etc.

select * from INFORMATION_SCHEMA.routines where ROUTINE_DEFINITION like '%xp%_'

OTHER TIPS

No. There is no default mechanism in SMS to be able to search across projects.

You could use sp_MSforeachdb like so:

sp_MSforeachdb 'SELECT * FROM ?.INFORMATION_SCHEMA.routines WHERE ROUTINE_TYPE = ''PROCEDURE'''

The above will select all procedures across all databases and return them in different result sets. Using different views, you can also select tables, columns and so forth.

I hope someone has a better answer to this than I do. In the past, I've used a CURSOR to search through all the databases and insert results into a temp table. I could then select from the temp table and show the results.

I don't have this code laying around anymore. If no one comes up with a better answer, I'll come back and edit this with some real code. I would think that there'd be a DMV for this. Anyone?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top