如何查找所有引用特定存储过程的存储过程

时间:2019-05-16 04:50:57

标签: sql sql-server stored-procedures ssms

我想查找所有存储过程列表,这些列表引用了给定的存储过程。我正在使用SSMS2017。有人可以建议对此进行查询吗?

4 个答案:

答案 0 :(得分:1)

在以下查询中,您可以在WHERE子句中代替'%YourProcedureName%',而不是-- Find specific word in the SPs SELECT DISTINCT P.[name], M.[definition] FROM sys.procedures P JOIN sys.sql_modules M ON M.[object_id] = P.[object_id] WHERE M.[definition] LIKE '%YourProcedureName%' ,它将返回其中具有给定过程名称的其他过程。

{  
    "name":"Test",
    "Cell-Number":"Test",
    "CNIC":"12112112",
    "Person-Name":"Test",
    "Focal-person-cell-phone":"121212",
    "Focal-person-CNIC":"12121212",
    "Religion":"Test",
    "Total-teachers":"4",
    "Total-students":"37",
    "Total-Hosteled-students":"11",
    "Government-\/-Private":"Govt",
    "Category":"Jamia",
    "Total-Gates":"3",
    "Registration-number":"211121",
    "Security-guard\/watchman":"10",
    "Condition":"Test"
}

答案 1 :(得分:1)

SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%TableNameOrWhatever%'

答案 2 :(得分:0)

您应该尝试使用此solution。有关更多信息,请访问此link

SELECT 
    o.name AS ReferencingObject, 
    sd.referenced_entity_name AS ReferencedObject
FROM sys.sql_expression_dependencies  AS sd
INNER JOIN sys.objects AS o
    ON o.object_id = sd.referencing_id
WHERE sd.referenced_entity_name = 'my_object_name';

OR

SELECT  name AS ProcedureName ,
        CONVERT(VARCHAR(10), SysObj.modify_date, 103) AS [Create/Modify Date] ,
        CONVERT(VARCHAR(15), CAST(SysObj.modify_date AS TIME), 100) [Create/Modify Time]
FROM    sys.objects SysObj
WHERE   SysObj.type = 'P'
        AND DATEDIFF(D, SysObj.modify_date, GETDATE()) < YEAR(GETDATE())

OR

SELECT  name AS ProcedureName ,
        CONVERT(VARCHAR(10), SysObj.modify_date, 103) AS [Create/Modify Date] ,
        CONVERT(VARCHAR(15), CAST(SysObj.modify_date AS TIME), 100) [Create/Modify Time]
FROM    sys.objects SysObj
WHERE   SysObj.type = 'P'
ORDER BY SysObj.modify_date DESC

答案 3 :(得分:0)

SELECT Name
FROM sys.procedures
where name like '%someCommonNameOfProcedure%'