473,794 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_SprocTempla te') IS NOT NULL
DROP PROCEDURE dbo.spr_SprocTe mplate
--*/

IF OBJECT_ID('dbo. spr_SprocTempla te') IS NULL
BEGIN
EXEC ('CREATE PROCEDURE dbo.spr_SprocTe mplate AS SELECT 1')
EXEC ('GRANT EXECUTE ON dbo.spr_SprocTe mplate TO db_sprocexecuto r') --
custom role that has permissions to execute sprocs
END
GO

ALTER PROCEDURE dbo.spr_SprocTe mplate
AS
BEGIN --Procedure
SET NOCOUNT ON

SELECT

END --Procedure

GO

GO
Hope that Helps!

-Eric Isaacs
Jul 25 '08 #1
0 2250

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13572
by: M Simpson | last post by:
/* for the google index */ ALTER TABLE DEFAULT COLUMN DEFAULT VALUE I've worked out several stored procedures for altering the default column values in a table. They were compiled from books and code snippets found here. It was a pain to work out so I've decided to share my work and research here. This post is just my way of saying thanks to several others here for posting with their wisdom and intelligence.
2
21356
by: me | last post by:
I would like to add an Identity to an existing column in a table using a stored procedure then add records to the table and then remove the identity after the records have been added or something similar. here is a rough idea of what the stored procedure should do. (I do not know the syntax to accomplish this can anyone help or explain this? Thanks much, CBL
7
2625
by: pb648174 | last post by:
I am trying to add a column to a temp table and then immeditaely query against that new column. If I do this in Query Analyzer it works fine as long as there is a go in between, but I can't use a go inside a stored proc.. How do i get SQL to finish processing the alter table command so I can use the new column? alter table #TempPaging add TIId int not null identity --go --fixes the problem in QA, but not in proc Select * From...
10
26143
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not null references another, FK_LASTLYOID bigint not null references lastly, unique (FK_OTHEROID,FK_ANOTHEROID))
3
4866
by: CK | last post by:
Hi All, Quick question, I have always heard it best practice to check for exist, if so, drop, then create the proc. I just wanted to know why that's a best practice. I am trying to put that theory in place at my work, but they are asking for a good reason to do this before actually implementing. All I could think of was that so when you're creating a proc you won't get an error if the procedure already exists, but doesn't it also have to...
7
6994
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get into the GUI because it is hard to describe in text. First of all what is the purpose of ALTOBJ()? This procedure was created mostly for ISVs who need to do produce change scripts to upgrade application from release to release, but it can also
11
4101
by: raylopez99 | last post by:
Keep in mind this is my first compiled SQL program Stored Procedure (SP), copied from a book by Frasier Visual C++.NET in Visual Studio 2005 (Chap12). So far, so theory, except for one bug (feature?) below. At some point I'm sure I'll be able to laugh about this, akin to forgeting a semi-colon in C/C++, but right now it's frustrating (time to sleep on it for a while). Problem-- For some reason I get the error when trying to save files...
2
5552
by: devlin | last post by:
HI. I have to Alter a procedure if it exists or Create the procedure if it doesn't in SQL Server 2005. I can manage to determine if it exists or not, but when i have the code to create and alter in the IF... ELSE statement it doesn't seem to work. It still trys to create it when it exists or alter when it doesn't. I would prefer not to drop the procedure if it exists... Any help or advice would be greatly appreciated.
2
8223
by: semaj.remle 'at' gmail | last post by:
For files saved in source control, is it better to use code to DROP/ CREATE a procedure like this: ------------------------------------------------------------------ IF OBJECT_ID ('procName') IS NOT NULL DROP PROC procName GO CREATE PROCEDURE procName AS BEGIN --proc code
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.