Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:24:41+00:00 2026-05-14T22:24:41+00:00

I’m in the course of doing some schema migrations, and would like to know

  • 0

I’m in the course of doing some schema migrations, and would like to know if it’s possible or advisable to run every stored procedure, view and function in my database as an alter statement to “compile” them all to make sure nothing is completely broken.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:24:41+00:00Added an answer on May 14, 2026 at 10:24 pm

    Well, I built a sproc to do this, not very elegant, but hopefully someone else will find it useful:

    CREATE PROCEDURE [dbo].[UTIL_RunAlterOnAll]
        @debugMessages BIT = 0
    AS
    BEGIN
        BEGIN TRAN
            SET NOCOUNT ON
    
            DECLARE @allAlterTexts TABLE (name VARCHAR(256), alterText NVARCHAR(MAX), id INT, type CHAR(2))
    
            DECLARE @rowsInError TABLE (errorMessage NVARCHAR(2048), errorNumber INT, name VARCHAR(256), alterText NVARCHAR(MAX), id INT, type CHAR(2))
    
            ;WITH Texts AS
            (
                SELECT o.name, o.type, sm.definition AS text, o.id
                FROM sysobjects AS o
                INNER JOIN sys.sql_modules AS sm
                ON sm.object_id = o.id
                WHERE o.type IN ('P', 'V', 'FN')
            )
            INSERT INTO @allAlterTexts (name, alterText, id, type)
            SELECT name, alterStatement, id, type
            FROM
            (
                SELECT name, REPLACE(text, 'CREATE PROCEDURE', 'ALTER PROCEDURE') AS alterStatement, id, type
                FROM Texts AS procs
                WHERE procs.type = 'P'
                UNION ALL
                SELECT name, REPLACE(text, 'CREATE VIEW', 'ALTER VIEW') AS alterStatement, id, type
                FROM Texts AS procs
                WHERE procs.type = 'V'
                UNION ALL
                SELECT name, REPLACE(text, 'CREATE FUNCTION', 'ALTER FUNCTION') AS alterStatement, id, type
                FROM Texts AS procs
                WHERE procs.type = 'FN'
            ) AS allAlters
    
            DECLARE curs CURSOR FORWARD_ONLY
            FOR
                SELECT *
                FROM @allAlterTexts
    
            DECLARE @name VARCHAR(MAX)
                , @alterText VARCHAR(MAX)
                , @id INT
                , @type VARCHAR(2)
    
            OPEN curs
                FETCH NEXT FROM curs
                INTO @name, @alterText, @id, @type
    
                WHILE @@FETCH_STATUS = 0
                BEGIN
                    IF @debugMessages = 1
                    BEGIN
                        PRINT 'Alter text for @name'
                        PRINT '-----'
                        PRINT @alterText
                        PRINT '-----'
                    END
    
                    BEGIN TRY
                        IF @debugMessages = 1
                        BEGIN
                            PRINT 'Running ' + @name
                        END
                            EXEC(@alterText)
                        IF @debugMessages = 1
                        BEGIN
                            PRINT 'Success'
                        END
                    END TRY
                    BEGIN CATCH
                        IF @debugMessages = 1
                        BEGIN
                            PRINT 'ERROR!'
                            PRINT ERROR_MESSAGE()
                            PRINT '----'
                            PRINT 'Text:'
                            PRINT @alterText
                        END
    
                        INSERT INTO @rowsInError (errorMessage, errorNumber, name, alterText, id, type)
                        VALUES(LTRIM(RTRIM(ERROR_MESSAGE())), ERROR_NUMBER(), @name, @alterText, @id, @type)
                    END CATCH
    
    
                    IF @debugMessages = 1
                    BEGIN
                        PRINT '-----'
                    END
    
                    FETCH NEXT FROM curs
                    INTO @name, @alterText, @id, @type
                END
            CLOSE curs
    
            DEALLOCATE curs
            SET NOCOUNT OFF
    
            -- WTF? 3930 means transaction error, these get raised whenever another error is raised, 
            -- as the transaction is set to invalid
            SELECT *
            FROM @rowsInError
            WHERE errorNumber != 3930
            ORDER BY name
    
        ROLLBACK TRAN
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.