Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 searching stored procedures

Author  Topic 

Sean_B
Posting Yak Master

111 Posts

Posted - 2006-12-05 : 06:38:26
Hi,

I want to search through the stored procedures in a database
I've tried using the following but it looks like the ROUTINE_DEFINITION truncates longer routines. Can anyone suggest an alternative.

SELECT ROUTINE_NAME,ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE='PROCEDURE'
and ROUTINE_DEFINITION LIKE '%execute%'

Also what should I read to understand system tables and the underlying INFORMATION_SCHEMA in particular

thanks



Sean

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 06:47:02
The best source of information is Books Online.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-05 : 10:33:02

1 Generate SQL script on procedures
2 Do Find

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-12-05 : 12:58:59
This might help:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=32319
Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2006-12-05 : 16:00:16
quote:
Originally posted by madhivanan


1 Generate SQL script on procedures
2 Do Find



That seems a very long-winded way of doing it when you can just do a search on syscomments (or the corresponding IS views)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 16:03:31
Timmy
quote:
Originally posted by Sean_B

Also what should I read to understand system tables and the underlying INFORMATION_SCHEMA in particular

Also syscomments truncates the SP code in chunks of 4000 bytes.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-12-05 : 16:05:31
searching syscomments is not bulletproof because if the proc is longer than 4000 chars, the text gets split between rows, so the string you are searching for could be cut in half. INFORMATION_SCHEMA is worse because the text is truncated, as the OP said.

what madhivanan suggests *is* bulletproof.


SqlSpec: a fast and comprehensive data dictionary generator for
SQL Server 2000/2005, Analysis Server 2005, Access 97/2000/XP/2003
http://www.elsasoft.org
Go to Top of Page

mrsquish
Starting Member

1 Post

Posted - 2011-06-09 : 19:50:05
This might be of some assistance :

CREATE FUNCTION [System].[ProcedureText](
@Proc sysname
) RETURNS varchar(max)
AS BEGIN
DECLARE @TSQL varchar(max)
SET @TSQL = ''

SELECT @TSQL = @TSQL + [text]
FROM syscomments
WHERE id = OBJECT_ID(@Proc)

RETURN @TSQL
END
GO

But you'd have to run over it with a cursor.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-14 : 03:52:57
quote:
Originally posted by mrsquish

This might be of some assistance :

CREATE FUNCTION [System].[ProcedureText](
@Proc sysname
) RETURNS varchar(max)
AS BEGIN
DECLARE @TSQL varchar(max)
SET @TSQL = ''

SELECT @TSQL = @TSQL + [text]
FROM syscomments
WHERE id = OBJECT_ID(@Proc)

RETURN @TSQL
END
GO

But you'd have to run over it with a cursor.



Did you see the previous reply?
You can also use object_definition function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -