zaagan
1/5/2020 - 11:47 AM

MS SQL Find Stored Procedure

MS SQL Find Stored Procedure

-- Find SP By Name
SELECT
    name
FROM
   sys.procedures 
WHERE
   name LIKE '%request%'
   
-- Find SP via System Information schema View
SELECT
    ROUTINE_NAME, 
    ROUTINE_DEFINITION , 
    ROUTINE_SCHEMA
FROM
    INFORMATION_SCHEMA.ROUTINES 
WHERE
    ROUTINE_TYPE='PROCEDURE' AND
    ROUTINE_NAME LIKE '%request%'
    
-- Find SP via System Compatibility View
SELECT
    OBJECT_NAME(id),
    text
FROM
    sys.syscomments 
WHERE
    OBJECTPROPERTY(id, 'IsProcedure') = 1 AND
    OBJECT_NAME(id) LIKE '%request%'
ORDER BY OBJECT_NAME(id)

-- Find SP via System Object Catalog View.
SELECT object_id,
       OBJECT_NAME(object_id),
       definition
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
      AND OBJECT_NAME(object_id) LIKE '%request%';