473,326 Members | 2,010 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,326 software developers and data experts.

How to upgrade a stored procedure this way?

Hi!

I need to write a t-sql-script like this:

(case-1)
IF {stored procedure SP is not exists} BEGIN
CREATE PROCEDURE SP
AS BEGIN
//dummy body
END
END

ALTER PROCEDURE SP
AS
BEGIN
//real body
END

and dislike the case below because it is possible that CREATE fails
after DROP and we lost any (old or new) SP versions:

(case-2)
IF {stored procedure SP is exists} BEGIN
DROP PROCEDURE SP
END

CREATE PROCEDURE SP
AS
BEGIN
//real body
END
How to write the script lile (1) correctly? Now I have a troubles while
inserting "CREATE PROCUDURE" inside "IF true BEGIN ... END" block.
*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #1
1 1524

"Evgeny Gopengauz" <ev***@ucs.ru> wrote in message
news:ao**************@news.uswest.net...
Hi!

I need to write a t-sql-script like this:

(case-1)
IF {stored procedure SP is not exists} BEGIN
CREATE PROCEDURE SP
AS BEGIN
//dummy body
END
END

ALTER PROCEDURE SP
AS
BEGIN
//real body
END

and dislike the case below because it is possible that CREATE fails
after DROP and we lost any (old or new) SP versions:

(case-2)
IF {stored procedure SP is exists} BEGIN
DROP PROCEDURE SP
END

CREATE PROCEDURE SP
AS
BEGIN
//real body
END
How to write the script lile (1) correctly? Now I have a troubles while
inserting "CREATE PROCUDURE" inside "IF true BEGIN ... END" block.
*** Sent via Developersdex http://www.developersdex.com ***


Personally, I would go for case 2 - it's easier to script. If you're using
source control to manage your SQL objects, you should never lose the old
version of the proc code because it will be in your source code repository.
If you aren't using source control (and you should be), then one way to make
sure you don't lose the old one is to put the whole DROP ... CREATE ...
batch inside a transaction - if the create fails for some reason, then just
ROLLBACK.

Simon
Jul 23 '05 #2

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

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
1
by: Aston | last post by:
I have this stored procedure that takes a few parameters like date and merchant ID, and basically goes through a set of if-then statements to build a SQL SELECT string. When we upgraded from SQL...
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...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
7
by: fayez | last post by:
Hi. going from 8.1.2 to 8.1.11, make our stored procedures very slow, here is an example: select a, b from t1 a join t2 b on a.bkr=b.bkr and (a.act_id=b.act_id or (substr(a.act, 1, 2)=b.act...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
3
by: Jeff Kish | last post by:
Hi. I am between beginner and intermediate level of knowledge of sql server. I am dealing with an sql server 2005 situation (oracle also but thats another thread/story). I need to assemble a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.