Solved

Update Stored Procedure on many schema

Posted on 2011-02-17
3
254 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modifying SQL 2008/2012 PARTITIONS 3 55
How to enforce inte 8 43
SSIS how to COMPARE a data column from different servers? 6 89
Stored procedure 4 32
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 …
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now