Solved

Update Stored Procedure on many schema

Posted on 2011-02-17
3
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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