Is there a way to make a procedure to search and replace a specific string in all procedures?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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:
This will yield a series of
CREATE PROCEDUREcommands separated byGO. You can’t necessarily do a search/create forCREATE PROCEDUREand change it toALTERin case you have actualCREATE PROCEDUREstrings within the stored procedure body. So instead you can pull these results into your favorite text editor and do a search and replace for:Replacing it with:
(Though this assumes that you don’t have comments before the
CREATE PROCEDUREline. 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 actuallyCREATE PROCEDUREand notCREATE PROCor random spacing betweenCREATEandPROCand that your system isn’t case sensitive and you usedcreate procorCreate Proc…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:
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
CREATEtoALTER), but it is not very common that you can just drop and re-create objects because of permissions and/or dependencies.CREATE OR REPLACEor 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