Oh, and I need a way to present it to my boss in an easy-to-use-excel-format.
Well, this code will search all your databases for the text combinations you provide and return the views that contain the keywords. You can easily modify this to include stored procedures or functions and you can extend the search combinations and what it says as a response to certain keywords being found.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
declare @SearchText nvarchar(max) = 'MuFunction(@SomeParam)' , @IncludeSystemDbs as tinyint = 0 --1 to include declare @tbSearchResults table ( fqo nvarchar(384) , object_type_description nvarchar(max) ) declare @SearchSql nvarchar(max) = formatmessage( ' use ? select concat_ws(''.'', quotename(''?''), quotename(object_schema_name(ASM.object_id)), quotename(object_name(ASM.object_id))), OBJ.type_desc from sys.all_sql_modules as ASM inner join sys.objects OBJ on ASM.object_id = OBJ.object_id where ASM.definition like ''%%%s%%'' and exists ( select 1/0 from sys.databases as DTB where ( DTB.name = ''?'' and ( is_distributor = 0 or ''?'' not in (''master'',''tempdb'',''model'', ''msdb'') or %d = 1 ) ) ) ', @SearchText, @IncludeSystemDbs) insert into @tbSearchResults exec sys.sp_MSforeachdb @command1 = @SearchSql select SRS.object_type_description , SRS.fqo from @tbSearchResults as SRS order by 1 , 2 |