MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 18th, 2004, 11:15 AM
mondo3 mondo3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 mondo3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Searching through stored procedures

Is there a way to search through stored procedured for specific text? or is there a way to convert all stored procedures to a text file(s)? thanks

Reply With Quote
  #2  
Old December 16th, 2004, 06:48 PM
fricklas fricklas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 fricklas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try this

Quote:
Originally Posted by mondo3
Is there a way to search through stored procedured for specific text? or is there a way to convert all stored procedures to a text file(s)? thanks

http://www.geniusatwork.nl/topic1.asp

Reply With Quote
  #3  
Old December 17th, 2004, 02:02 PM
Aforsythe Aforsythe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 104 Aforsythe User rank is Private First Class (20 - 50 Reputation Level)Aforsythe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 22 h 8 m 10 sec
Reputation Power: 4
Another option is to generate a Schema from the database, include stored procedures and you'll be able to search for text unless the stored procedures have been encrypted.


Enterprise manager --> Right click your database --> all tasks --> Generate SQL Script

That should get you started, play around with it look all the options on all the tabs, you can grab triggers and table definitions as well. Actually you can grab everything you need in order to delete that database and recreate it (without data of course)

Reply With Quote
  #4  
Old December 17th, 2004, 04:53 PM
elfy elfy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Poland
Posts: 11 elfy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 7 sec
Reputation Power: 0
Code:
USE master
GO

IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'sp_search_code' AND type = 'P')
DROP PROC sp_search_code
GO
CREATE PROC sp_search_code
(
@SearchStr 	varchar(100),
@RowsReturned	int = NULL	OUT
)
AS
/*************************************************************************************************
		Copyright © 1997 - 2002 Narayana Vyas Kondreddi. All rights reserved.
                                          
Purpose:	To search the stored proceudre, UDF, trigger code for a given keyword.

Written by:	Narayana Vyas Kondreddi
		http://vyaskn.tripod.com

Tested on: 	SQL Server 7.0, SQL Server 2000

Date created:	January-22-2002 21:37 GMT

Date modified:	February-17-2002 19:31 GMT

Email: 		vyaskn@hotmail.com

Examples:

To search your database code for the keyword 'unauthorized':
EXEC sp_search_code 'unauthorized'

To search your database code for the keyword 'FlowerOrders' and also find out the number of hits:
DECLARE @Hits int
EXEC sp_search_code 'FlowerOrders', @Hits OUT
SELECT 'Found ' + LTRIM(STR(@Hits)) + ' object(s) containing this keyword' AS Result
*************************************************************************************************/
BEGIN
	SET NOCOUNT ON

	SELECT	DISTINCT USER_NAME(o.uid) + '.' + OBJECT_NAME(c.id) AS 'Object name',
		CASE 
 			WHEN OBJECTPROPERTY(c.id, 'IsReplProc') = 1 
				THEN 'Replication stored procedure'
 			WHEN OBJECTPROPERTY(c.id, 'IsExtendedProc') = 1 
				THEN 'Extended stored procedure'				
			WHEN OBJECTPROPERTY(c.id, 'IsProcedure') = 1 
				THEN 'Stored Procedure' 
			WHEN OBJECTPROPERTY(c.id, 'IsTrigger') = 1 
				THEN 'Trigger' 
			WHEN OBJECTPROPERTY(c.id, 'IsTableFunction') = 1 
				THEN 'Table-valued function' 
			WHEN OBJECTPROPERTY(c.id, 'IsScalarFunction') = 1 
				THEN 'Scalar-valued function'
 			WHEN OBJECTPROPERTY(c.id, 'IsInlineFunction') = 1 
				THEN 'Inline function'	
		END AS 'Object type',
		'EXEC sp_helptext ''' + USER_NAME(o.uid) + '.' + OBJECT_NAME(c.id) + '''' AS 'Run this command to see the object text'
	FROM	syscomments c
		INNER JOIN
		sysobjects o
		ON c.id = o.id
	WHERE	c.text LIKE '%' + @SearchStr + '%'	AND
		encrypted = 0				AND
		(
		OBJECTPROPERTY(c.id, 'IsReplProc') = 1		OR
		OBJECTPROPERTY(c.id, 'IsExtendedProc') = 1	OR
		OBJECTPROPERTY(c.id, 'IsProcedure') = 1		OR
		OBJECTPROPERTY(c.id, 'IsTrigger') = 1		OR
		OBJECTPROPERTY(c.id, 'IsTableFunction') = 1	OR
		OBJECTPROPERTY(c.id, 'IsScalarFunction') = 1	OR
		OBJECTPROPERTY(c.id, 'IsInlineFunction') = 1	
		)

	ORDER BY	'Object type', 'Object name'

	SET @RowsReturned = @@ROWCOUNT
END
GO

GRANT EXEC ON sp_search_code TO Public

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Searching through stored procedures


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT