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 6351847
In Process

The Archive Base Latest Questions

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

Is there a way to make a procedure to search and replace a specific

  • 0

Is there a way to make a procedure to search and replace a specific string in all procedures?

  • 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-24T22:05:17+00:00Added an answer on May 24, 2026 at 10:05 pm

    Maybe it would be easier to fix the application. Why does the software care about comments? Does it also barf on extended properties?

    Assuming the comment is always the same, run this in Management Studio with results to text:

    SET NOCOUNT ON;
    
    SELECT 'GO
        ' + REPLACE([definition], '/* offending comment */', '')
        FROM sys.sql_modules
        WHERE [definition] LIKE '%/* offending comment */%';
    

    This will yield a series of CREATE PROCEDURE commands separated by GO. You can’t necessarily do a search/create for CREATE PROCEDURE and change it to ALTER in case you have actual CREATE PROCEDURE strings within the stored procedure body. So instead you can pull these results into your favorite text editor and do a search and replace for:

    GO
    CREATE PROCEDURE
    

    Replacing it with:

    GO
    ALTER PROCEDURE
    

    (Though this assumes that you don’t have comments before the CREATE PROCEDURE line. If you do, you’ll need to get more creative with your search and replace.)

    If you don’t need to worry about procedures that contain a valid string CREATE PROCEDURE – and assuming that your syntax is actually CREATE PROCEDURE and not CREATE PROC or random spacing between CREATE and PROC and that your system isn’t case sensitive and you used create proc or Create Proc…

    SET NOCOUNT ON;
    
    SELECT 'GO
        ' + REPLACE(REPLACE([definition], '/* offending comment */', ''),
        'CREATE PROCEDURE', 'ALTER PROCEDURE')
        FROM sys.sql_modules
        WHERE [definition] LIKE '%/* offending comment */%';
    

    If you don’t care about the existing tangible things associated with your stored procedures, e.g. permissions, you could also do it this way:

    SELECT 'DROP PROCEDURE ' 
        + QUOTENAME(OBJECT_SCHEMA_NAME([object_id])) 
        + '.' + QUOTENAME(OBJECT_NAME([object_id])) + ';
        ' + 'GO
        ' + REPLACE([definition], '/* offending comment */', '')
    FROM sys.sql_modules
    WHERE [definition] LIKE '%/* offending comment */%';
    

    This will generate a script that is much closer to ready to go, since it just drops the procedure and re-creates it (so doesn’t need to change CREATE to ALTER), but it is not very common that you can just drop and re-create objects because of permissions and/or dependencies.

    CREATE OR REPLACE or something similar in DDL would make this much easier to script out. If you feel this would be a valuable addition to SQL Server, please vote for the following suggestion (and add your use case, or why you think this would be valuable, to the comments):

    http://connect.microsoft.com/SQLServer/feedback/details/127219/create-or-replace

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to make Visual Studio 2008 Express store all the files
is there a way to make a query which DB the Stored Procedure is
Is there any way that I can make sure that a stored procedure completely
Before I delete/replace a stored procedure, I would usually do a string search of
Is there a way to make a TSQL variable constant?
Is there a way to make a Radio Button enabled/disabled (not checked/unchecked) via CSS?
Is there a way to make a popup window maximised as soon as it
Is there a way to make running junit test to stop after a test
Is there a way to make a python module load a dll in my
Is there a way to make sure a (large, 300K) background picture is always

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.