473,394 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stored Proc Question : Why If Exisits...Drop...Create Proc?

CK
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 do with
Compilation and perhaps Execution. Does anyone have a good argument for
doing stored procs this way? All feedback is appreciated.
TIA,
~CK
Jun 15 '06 #1
3 4845
It is a limited scope attempt for correctly implementing UNIQUENESS on
all table rows...If you want to understand why it is a *good* practice
you need to learn more about rules of relational modeling and
especially database design and definition of primary keys...
Look for "Introduction to Database Systems" from CJ Date (at Amazon)

Hope this helps...
CK wrote:
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 do with
Compilation and perhaps Execution. Does anyone have a good argument for
doing stored procs this way? All feedback is appreciated.
TIA,
~CK


Jun 15 '06 #2
CK (c_**********@hotmail.com) writes:
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 do with Compilation and perhaps Execution. Does anyone
have a good argument for doing stored procs this way? All feedback is
appreciated.


Nah, the best is to use ALTER if the procedure already exists, because
then you retein permissions on the procedure. In SQL 2005, you also
retain depenency information.

The problem is that there is no CREATE_OR_ALTER statment, so a pure
SQL script for installation, is most easiest written with IF EXISTS DROP
CREATE. To use ALTER in a pure SQL script, you would have to have the
procedure code in dynamic SQL, and that would be very difficult to
maintain.

The really best practice is to have some client-side load tool that
reads the procedure code and then replaces CREATE with ALTER as needed.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 15 '06 #3
Hopefully this person posted the answer below to the wrong original
question, because his answer makes absolutely no sense....

Cimode wrote:
It is a limited scope attempt for correctly implementing UNIQUENESS on
all table rows...If you want to understand why it is a *good* practice
you need to learn more about rules of relational modeling and
especially database design and definition of primary keys...
Look for "Introduction to Database Systems" from CJ Date (at Amazon)

Hope this helps...
CK wrote:
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 do with
Compilation and perhaps Execution. Does anyone have a good argument for
doing stored procs this way? All feedback is appreciated.
TIA,
~CK


Jun 18 '06 #4

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

Similar topics

2
by: Daniel | last post by:
hi ng, i am newbie to sqlserver and my problem seems simple, but i didn't find information about it: How can i display the RETURN @x value of a stored procedure in the sql analyzer of the...
4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
5
by: Chad | last post by:
Could any suggest to me a good way to programmatically identify which SPs update a database column. I would like to create a cross reference for our database.
2
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create, read, update, delete data in a SQL Server 2000 data...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
3
by: Wie | last post by:
I need help. How do I create a stored procedure with SQLCommand? I have tried following string, but it doesn't work. I am using vs.net 2003 professional now. dbCommand.CommandText = _...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
3
by: yinzara | last post by:
I have the following trigger that calls a DB2 stored procedure: DROP TRIGGER GGWU.TRI_A_MULTI_PROP@ CREATE TRIGGER GGWU.TRI_A_MULTI_PROP AFTER INSERT ON GGWU.MULTIPLIER_PROPERTY REFERENCING ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.