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
 Script Library
 sp_ShowCode

Author  Topic 

Spyder
SQLTeam Author

75 Posts

Posted - 2002-02-17 : 23:04:17
This proc is intended to be implemented in the master database; it allows you functionality similar to the DESCRIBE in Oracle for looking at the code of stored procedures, triggers, and functions.


/****** Stored Procedure dbo.sp_ShowCode v1.1 ******/

CREATE PROCEDURE sp_ShowCode
@objectname VARCHAR(255) = NULL

AS

SET NOCOUNT ON

IF EXISTS (SELECT type FROM sysobjects WHERE id = OBJECT_ID(@objectname) AND type IN ('P','TR','FN'))
SELECT text AS code
FROM syscomments
WHERE id = OBJECT_ID(@objectname)
ELSE
BEGIN
IF @objectname IS NOT NULL
BEGIN
PRINT 'Invalid object name OR object name you provided is not a stored procedure, trigger, or function!'
PRINT ''
END
PRINT 'Valid object names are:'
PRINT ''
SELECT CASE type WHEN 'P' THEN 'Stored Procedure' WHEN 'TR' THEN 'Trigger' WHEN 'FN' THEN 'Function' END AS type, name
FROM sysobjects
WHERE type IN ('P','TR','FN')
ORDER BY type, name
END





Edited by - spyder on 02/17/2002 23:10:36

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-02-17 : 23:18:11
Why not use "sp_helptext"?

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

Spyder
SQLTeam Author

75 Posts

Posted - 2002-02-17 : 23:22:37
quote:
Why not use "sp_helptext"?


sp_helptext isn't as nice to you when you supply an invalid input parm; also this will give you a list of valid procs/trigs/funcs if you run it without an input parm.

Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-02-17 : 23:33:59
Fair enough....

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

Spyder
SQLTeam Author

75 Posts

Posted - 2002-02-17 : 23:46:28
Come to think of it, I think that the unfriendliness of sp_helptext is what sparked me to cobble this thing together in the first place!

Go to Top of Page
   

- Advertisement -