Solved

How to script all sp's in a database

Posted on 2008-10-13
3
207 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to enforce inte 8 51
MS SQL page split per second is high 19 95
Selection from table2 where criteria for table1 10 42
Need help how to find where my error is in UFD 6 27
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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