returning all procedures
-
9 июня 2012 г. 11:33
hi
i want to know is there a procedure to return all procedures definition in sqlServer 2008 R2?
tanx
mina
- Перемещено Iric WenModerator 11 июня 2012 г. 3:31 (From:Microsoft Drivers for PHP for SQL Server)
Все ответы
-
9 июня 2012 г. 20:36
Hi,
I'd suggest taking a look at sys.all_sql_modules http://msdn.microsoft.com/en-us/library/ms184389(v=sql.105).aspx or sys.sql_modules http://msdn.microsoft.com/en-us/library/ms175081(v=sql.105).aspx
There is a query example in the sys.sql_modules link.
- Предложено в качестве ответа Steven Wang - Shangzhou 11 июня 2012 г. 3:42
-
11 июня 2012 г. 3:38Модератор
Hi mina,
We can use sys.sql_modules, OBJECT_DEFINITION or sp_helptext to view definition of a stored procedure.
For more information, please see:
How to: View the Definition of a Stored Procedure (SQL Server Management Studio)
Best Regards,
Iric
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Помечено в качестве ответа Iric WenModerator 18 июня 2012 г. 1:34
-
11 июня 2012 г. 3:58
Hi,
Here is a query to return the proc definition
select OBJECT_DEFINITION(object_id) from sys.procedures
Use the text output in SSMS while viewing the definition, otherwise you may lose the formatting , indentation etc
Regards
satheesh -
11 июня 2012 г. 4:05
Mina,
As suggest by other forum members you can go along with sys.all_sql_modules, sys.sql_modules and sp_helptext. The following is a simple script to execute sp_helptext dynamically through out all your stored procedures to get the definitions of stored procedures.
You can try as follows
--DECLARING A TABLE VARIABLE DECLARE @SPNAME TABLE (ID INT IDENTITY(1,1),SP CHAR(200)) --INSERTING ALL STORED PROCEUDRE NAMES IN TABLE VARIABLE INSERT INTO @SPNAME SELECT NAME FROM SYS.PROCEDURES WHERE IS_MS_SHIPPED=0 --DECLARING VARIABLES DECLARE @SQLTEXT NVARCHAR(200) DECLARE @I INT, @J INT SET @J=1 SELECT @I=COUNT(NAME) FROM SYS.PROCEDURES WHERE IS_MS_SHIPPED=0 WHILE @J<=@I BEGIN SELECT @SQLTEXT='SP_HELPTEXT ' + SP FROM @SPNAME WHERE ID=@I EXEC(@SQLTEXT) SET @J=@J+1 END
Thanks
Manish
Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.- Помечено в качестве ответа Iric WenModerator 18 июня 2012 г. 1:34
-
14 июня 2012 г. 3:38Модератор
Take a look at this blog post
How to script all stored procedures in a database
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Помечено в качестве ответа Iric WenModerator 18 июня 2012 г. 1:34
-
14 июня 2012 г. 4:26
you can geneare stored procedures scripts by
right click on the databse->tasks->generate tasks->select database->....->select stored procedures->select all
now you can script the procedure into a file or query window.
ESHANI. Please click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

