Skip to content

Instantly share code, notes, and snippets.

@webcoyote
Created December 11, 2012 19:15
Show Gist options
  • Save webcoyote/4261183 to your computer and use it in GitHub Desktop.
Save webcoyote/4261183 to your computer and use it in GitHub Desktop.
Update SQL stored procedure
-- 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
-- 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