Solved

How to script all sp's in a database

Posted on 2008-10-13
3
208 Views
Last Modified: 2012-05-05
Hi, is there an easy way to script all of the stored procedures in a database?

I'm refreshing the data in a dev environment and don't want to lose the new stored procs ... so need to create them with Create or Alter. Is there a sql server equivalent of 'create or alter' in Mysql?

Thks.
0
Comment
Question by:craigdev
3 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 400 total points
ID: 22701458
Hi,

>> is there an easy way to script all of the stored procedures in a database?
yes. In SQL Server Management Studio, right click the database and select "Tasks -> Generate Scripts...". Follow the wizard through until the "Choose Object Types" dialog, and just tick the "Stored Procedures" box.

>> Is there a sql server equivalent of 'create or alter' in Mysql?
No. When deploying updates to sprocs that may or may not already exist, you'd usually drop and recreate them.

e.g.
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[YourStoredProcedureName]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE YourStoredProcedureName
GO

CREATE PROCEDURE YourStoredProcedureName
...
...
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 50 total points
ID: 22701476
another way to do it in 2005:

select object_definition(object_id) from sys.procedures
0
 
LVL 9

Assisted Solution

by:Sander Stad
Sander Stad earned 50 total points
ID: 22701488
You can also use the added code. It reaturn all the stored procedures from a database.

WITH ROUTINES AS (
	SELECT 
		o.type_desc AS ROUTINE_TYPE ,
		o.[name] AS ROUTINE_NAME ,
		m.definition AS ROUTINE_DEFINITION 
	FROM sys.sql_modules AS m 
		INNER JOIN sys.objects AS o ON m.object_id = o.OBJECT_ID
)
 
SELECT * FROM ROUTINES

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question