Created
December 11, 2012 19:15
-
-
Save webcoyote/4261183 to your computer and use it in GitHub Desktop.
Update SQL stored procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- if the stored procedure does not exist then create a placeholder | |
if not exists ( | |
select * from sys.objects where object_id = OBJECT_ID(N' p_MyProc') | |
and type = N'P' | |
) then | |
create procedure p_MyProc as RAISERROR ('MyProc not defined', 16, 1); | |
grant execute on p_MyProc to SomeRole | |
end | |
-- update stored proc | |
alter procedure p_MyProc as begin | |
-- awesome code here | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Delete the stored procedure if it already exists | |
if exists ( | |
select * from sys.objects where object_id = OBJECT_ID(N'p_MyProc') | |
and type = N'P' | |
) then | |
drop procedure p_MyProc | |
end | |
-- Now create it again | |
create procedure p_MyProc as begin | |
-- awesome code here | |
end | |
-- And set permissions | |
grant execute on p_MyProc to SomeRole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment