search for a key word in all the Stored Proc's for a given DB?

后端 未结 2 1452
攒了一身酷
攒了一身酷 2021-01-14 18:08

How to do a global search for a key word in all the Stored Proc\'s for a given DB?

I used the following but I am unable to get the desired results...



        
相关标签:
2条回答
  • 2021-01-14 18:37

    Have a look at this link - http://www.sqlservercentral.com/scripts/T-SQL+Aids/31131/ and see if that helps.

    The SP in the linked article was written by Prasad Bhogadi and is as follows:

    CREATE PROCEDURE SEARCHFORSTRING @SEARCHSTRING VARCHAR(100)
    AS
                SELECT  DISTINCT(sysobjects.name)
                    FROM 
                    sysobjects,syscomments
                WHERE 
                    sysobjects.id =     syscomments.id
                AND 
                    sysobjects.type = 'P'
                AND 
                    sysobjects.category=0
    AND
            CHARINDEX(@SEARCHSTRING ,syscomments.text)>0
    

    You can use this to create an SP in your database or adapt it for a one-time query.

    0 讨论(0)
  • 2021-01-14 18:49

    Only sys.sql_modules contains the whole definition of the procedure. Other views like INFORMATION_SCHEMA.ROUTINES contain a truncated definition.

    select object_name(o.object_id), m.*
    from sys.sql_modules m
    join sys.objects o on m.object_id = o.object_id
    where o.type= 'P'
    and m.definition like N'%<keyword>%'
    
    0 讨论(0)
提交回复
热议问题