Connecting Tech Pros Worldwide Help | Site Map

Re: ALTER proc vs IF EXISTS DROP/CREATE

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 25th, 2008, 11:35 PM
Eric Isaacs
Guest
 
Posts: n/a
Default Re: ALTER proc vs IF EXISTS DROP/CREATE

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.