I have 1500 odd T-SQL scripts which are formatted as follows:
DROP PROCEDURE <stored proc name>
CREATE PROCEDURE
<stored proc definition>
I've been tasked to insert an IF EXISTS condition on all of them, before they try to drop the procedure, so the scripts won't fail the first time they run.
I'm looking for an efficient way (in a windows 7 environment) to modify all these scripts to add the following condition before the drop statement. I'm not too keen on modifying them manually!
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'<stored proc name>') AND type in (N'P', N'PC'))
EDIT: Sublime text editor with Regex seems to be a good tool to use. I've never used Regex before but I've figured out that
(?<=DROP PROCEDURE ).*
Will find everything on the line after "stored procedure". I want to put this in the Replace statement but it doesn't seem to be reading it (the actual regex is just inserted into the code). How can I do this?