Unix Technical Forum

Re: ALTER proc vs IF EXISTS DROP/CREATE

This is a discussion on Re: ALTER proc vs IF EXISTS DROP/CREATE within the SQL Server forums, part of the Microsoft SQL Server category; --> Optional Create and Alter is nice because it fails, the original is still in place as are the original ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-28-2008, 06:39 PM
Eric Isaacs
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com