Thursday, April 23, 2009

Handy SQL script when creating sprocs

If you don't want to fuss with changing your stored procedure (sproc) script, specifically changing Create to Alter after the sproc has been created, use this handy snippet:


If exists(Select * from information_Schema.routines where specific_name = 'mySproc')
BEGIN
Drop proc [mySproc]
END
--(Create sproc script below)
--...


Change "mySproc" to the name of your sproc
This is especially nice when you've got a change script that just keeps growing and growing, and you don't want any interruptions when it comes time to run the script on a live environment.

No comments: