Solved

Update Stored Procedure on many schema

Posted on 2011-02-17
3
257 Views
Last Modified: 2012-05-11
I need to updated a stored procedure in each of roughly 1000 schema distributed across 10 databases in MS SQL 2005.

I have the alter procedure t-sql to update one schema. To apply the change to a different schema the procedure name and several calls to other procedures have to be updated with the correct schema. I'm currently doing this with a find and replace from the management studio while testing.

Is there a way to efficiently do this across many schema without manually updating the t-sql each time? If so, please give detail.
0
Comment
Question by:m3tech
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 34920987
I think you can use SQLCMD for this task.  It provides a way to script T-SQL.

More details here: http://msdn.microsoft.com/en-us/library/ms188714.aspx

Something like this:

:setvar SQLCMDLOGINTIMEOUT 60
:setvar server "testserver"
:setvar MYDATABASE AdventureWorks2008R2
:setvar ProcName MyProducedureName

:connect $(server) -l $(SQLCMDLOGINTIMEOUT)

USE $(MYDATABASE); 

ALTER PROCEDURE [dbo].[$(ProcName)]
AS
BEGIN
   ....
END

Open in new window

0
 
LVL 2

Author Comment

by:m3tech
ID: 34926501
Thanks, that looks like it will do the trick. I'll give it a shot with an addtional variable for the procedure's schema.

I was already considering modifying a script file with another scripting language and feeding it to sqlcmd. Feeding different variables to sqlcmd will definitely be easier.
0
 
LVL 2

Author Closing Comment

by:m3tech
ID: 34928646
I specifically asked about varying schema and the solution provided did not account for this. However, the change needed was minor and easy to make.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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