Connecting Tech Pros Worldwide Help | Site Map

Re: ALTER proc vs IF EXISTS DROP/CREATE

  #1  
Old July 26th, 2008, 12:35 AM
Eric Isaacs
Guest
 
Posts: n/a
Optional Create and Alter is nice because it fails, the original is
still in place as are the original permissions. Drop and create is
also valid in some cases if you want to clear/reset the permissions.

I use an approach which lets me choose which one I want to implement
on the fly. If I remove the first two dashes, the drop is disabled
and it creates only if it doesn't already exist. Otherwise it drops,
creates a filler sproc, and then alters with the real sproc...

--/* remove the two dashes at the beginning of this line to convert it
from a drop/create/alter to just a create/alter.
IF OBJECT_ID('dbo.spr_SprocTemplate') IS NOT NULL
DROP PROCEDURE dbo.spr_SprocTemplate
--*/

IF OBJECT_ID('dbo.spr_SprocTemplate') IS NULL
BEGIN
EXEC ('CREATE PROCEDURE dbo.spr_SprocTemplate AS SELECT 1')
EXEC ('GRANT EXECUTE ON dbo.spr_SprocTemplate TO db_sprocexecutor') --
custom role that has permissions to execute sprocs
END
GO

ALTER PROCEDURE dbo.spr_SprocTemplate
AS
BEGIN --Procedure
SET NOCOUNT ON

SELECT

END --Procedure

GO

GO


Hope that Helps!

-Eric Isaacs
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
ALTER proc vs IF EXISTS DROP/CREATE semaj.remle 'at' gmail answers 2 July 26th, 2008 12:05 AM