Hi,
I am actually having 100's of SP in my database. I have to find a set of 10 SP's in that which have a particular comment inside them. Is there any search query for this.
Hi,
I am actually having 100's of SP in my database. I have to find a set of 10 SP's in that which have a particular comment inside them. Is there any search query for this.
Found this article which does exactly what your after if your using SQL Server
I'll certainly be keeping a copy of this code for my own use :)
Also, It doesn't just work for comments but it appears to work for all text in an SP.
Edit
I've included a copy of the code for simplicity but all credit goes to Les Smith
CREATE PROCEDURE Find_Text_In_SP
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' +@StringToSearch + '%'
SELECT Distinct SO.Name
FROM sysobjects SO (NOLOCK)
INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
AND SO.Type = 'P'
AND SC.Text LIKE @stringtosearch
ORDER BY SO.Name
GO
Don't remember the exact tables names but it would be something like this. Give it a try.
SELECT sysobjects.name FROM syscomments, sysobjects WHERE syscomments.id=sysobjects.id WHERE syscomments.TEXT LIKE ‘%particular comment%’
select OBJECT_NAME(id), * from syscomments WHERE text LIKE 'WhateverYouAreSearchingFor'
you can use the information_schema for this:
select *
from information_schema.routines
where routine_definition like '%your comment to find%'
Bear in mind that this only looks through the first 4096 characters (i believe...) - to search through more characters, you have to query the underlying system tables directly. Have a look at the definition of the information_schema.routines view to see which system tables it is querying
Edit: @Rich's answer is what you will need if you need to query more than 4096 characters
I'm not sure if this is the best solution, but the following should work (although it may be slow):
Note that the syscomments search methods will fail if the String Search spans the boundary of records in syscomments.
To be 100% I guess you will have to Script the Sprocs out of the database
Suggest considering storing each Sproc in a separate file (and store in revision control repository etc.) rather than just Altering them in-situ in the DB