Find a stored procedure name with its content in SQL Server 2000
Asked Answered
B

5

13

For a stored procedure, I have its full source code. But the name of that stored procedure has been lost. In this database, there are hundreds of stored procedures.

So is there a way by which I can find out the name of the stored procedure by using its contents or by using any of the variables in the contents?

This is puzzling me a lot. A help would be sincerley appreciated.

Beautify answered 10/1, 2013 at 15:5 Comment(0)
S
26

Try this:

select * from sysobjects where id in 
(select id from syscomments where text like '%exec%')
order by [name]

where 'exec' is the text you're searching for. This query will search views also, just fyi

Statistical answered 10/1, 2013 at 15:9 Comment(0)
R
6

If the texts of the stored procedures are not encrypted, Sql Server keeps the full text of the procedure in the syscomments table with an id field that is referencing the sysobjects table, where the actual name is stored.

So, find some representative line from the stored procedure, that is unlikely to be in another place, and do:

select o.name, c.text 
from syscomments c
   inner join sysobjects o on o.id = c.id
where c.text like '%<representative_line>%'
  and o.type='P' -- this means filter procedures only

This should hopefully return just a few procedures that you can check by hand.

Rorke answered 10/1, 2013 at 15:16 Comment(1)
this is also good. But can't select more than one 'Answer'. Thnaks : )Beautify
S
2

There is another approach, more readable and memorable:

SELECT ROUTINE_NAME, ROUTINE_DEFINITION 
    FROM INFORMATION_SCHEMA.ROUTINES 
    WHERE ROUTINE_DEFINITION LIKE '%AlgunaPalabraQueTeAcuerdes%' 
    AND ROUTINE_TYPE='PROCEDURE'

This works at least in sql 2008 and newer versions. Fuente

Soniasonic answered 12/3, 2015 at 19:3 Comment(0)
C
0

Try this Query it will get the Procedure Name that contains the Given word or Field

   SELECT Name 
        FROM sys.procedures 
        WHERE OBJECT_DEFINITION(object_id) LIKE '%Any-Field (OR) WORD%'
Christcrossrow answered 10/1, 2013 at 15:11 Comment(2)
sys.procedures doesn't exist on SQL 2000Scuba
True. Mentioned Prob is for SQL 2000 !!Beautify
M
0
select object_name(id) from syscomments where text like '%exec%'
Muncey answered 11/9, 2014 at 3:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.