Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 264
Kings Avatar asked Jan 10 '13 15:01

Kings


People also ask

How do I find Stored Procedures with text in SQL Server?

The first and the simplest way to find a stored procedure with a specific text is by using the sys. procedures. The sys. procedures is a system view in SQL Server which stores data related to objects which are procedures in some way in SQL Server.

How do I find stored procedure details in SQL Server?

Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.

How do you identify a stored procedure?

You can find the stored procedure in the Object Explorer, under Programmability > Stored Procedures as shown in the following picture: Sometimes, you need to click the Refresh button to manually update the database objects in the Object Explorer.


2 Answers

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.

like image 71
SWeko Avatar answered Sep 26 '22 13:09

SWeko


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

like image 29
Melanie Avatar answered Sep 24 '22 13:09

Melanie