How do I find a stored procedure containing ?

后端 未结 20 2083
梦谈多话
梦谈多话 2020-11-28 17:21

I need to search a SQL server 2008 for stored procedures containing where maybe the name of a database field or variable name.

20条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 17:45

    SELECT s.name + '.' + o.name ProcedureName
    , c.text ProcedureSteps
    FROM   sys.syscomments c 
    INNER JOIN
    sys.objects o 
    ON 
    c.id = o.object_id
    INNER JOIN
    sys.schemas s 
    ON 
    o.schema_id = s.schema_id
    WHERE  o.type = 'P'
    AND c.text LIKE N'%XXXX%'
    ORDER BY s.name + '.' + o.name
    , c.colid
    

    This query returns the name and the content of any stored procedure where "XXXX" is is referenced within the stored procedure.

    This is quit usefull when finding procedures that reference a specific table/view/procedure

提交回复
热议问题