开发者

Search stored procedures/functions in all databases

I want to search for specific text in all procedures/functions etc. in all databases. I managed to create the required query from this answer but it looks li开发者_如何学Goke OBJECT_DEFINITION(OBJECT_ID(SPECIFIC_NAME)) returns NULL for all DBs except the current one.

sp_msforeachdb 'SELECT ''?'' AS DB, SPECIFIC_NAME, OBJECT_DEFINITION(OBJECT_ID(SPECIFIC_NAME)) FROM [?].INFORMATION_SCHEMA.ROUTINES'


You absolutely need Red-Gate's SQL Search tool - it's FREE, and absolutely great and perfectly suited for this need.

Search stored procedures/functions in all databases


The problem is OBJECT_ID cannot be used that way. It only works on the current database. Try returning ROUTINE_DEFINITION directly from INFORMATION_SCHEMA.ROUTINES. This does have a limit of 4000 characters. I'll try to find my other answer on SO which gives my workaround using the MS metadata views.

Have a look at this:

Can you search SQL Server 2005 Stored Procedure content?


try this:

select * from syscomments where [text] like '%yourKeyword%'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜