Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Change schema in stored procedure Expand / Collapse
Author
Message
Posted Monday, December 27, 2010 5:24 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, July 26, 2011 11:52 AM
Points: 15, Visits: 94
Hello

I have a bunch of stored procedure(more than 200) in my database.


I have to change the schema of those now. They have the schema ABC. I have to change it to XYZ,.

I know [ALTER SCHEMA XYZ TRANSFER ABC.STOREDPROCEDURE] query would do.

But the no of stored procedure is huge . I cannot do one by one. Is there any other way to do this task.

thanks
Post #1039605
Posted Tuesday, December 28, 2010 8:04 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 5:39 AM
Points: 15,662, Visits: 28,057
Export the stored procedures out to a script or set of alter scripts. Make the changes in the scripts. Run the scripts against the server.

For a mechanism to automate this you might look at Red Gate's tool, SQL Prompt, which has a bunch of automatic refactoring mechanisms, just like this.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1039781
Posted Tuesday, December 28, 2010 8:13 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, August 22, 2014 7:21 AM
Points: 28, Visits: 445
declare @name sysname
select top 1 @name=SPECIFIC_NAME from INFORMATION_SCHEMA.ROUTINES
where ROUTINE_TYPE='PROCEDURE' AND ROUTINE_SCHEMA='ABC'
while (@name is not null)
begin
execute( 'ALTER SCHEMA XYZ TRANSFER ABC.' + @name);

select top 1 @name=SPECIFIC_NAME from INFORMATION_SCHEMA.ROUTINES
where ROUTINE_TYPE='PROCEDURE' AND ROUTINE_SCHEMA='ABC'
End
Post #1039793
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse