Change schema in stored procedure

  • 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

  • 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[/url], 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply