Saturday, February 25, 2012

"CREATE OR ALTER" works in oracle, but not in ms sql

Hi

Normally we deliver scripts and the installers may NOT update the scripts.

This was fine for SQL scripts for oracle: because we are not aware of the situation in production, whether a stored proc was already previously installed or not.

therefore we wrote:

CREATE OR ALTER PROCEDURE ....... (or something like that).

but it seems in SQL server I can only write one of both:

CREATE PROCEDURE ....

or

ALTER PROCEDURE

this means that the script fails if it's NOT yet installed when and i use ALTER, and it fails when it IS already installed and I write CREATE

isn't there a solution to use "CREATE OR ALTER" in one script ?

IF EXISTS (SELECT name FROM sysobjects WHERE name = 'myStoredProc' AND type = 'P')

BEGIN

DROP PROCEDURE myStoredProc

END

GO

CREATE PROCEDURE myStoredProc (@.Params ...)

AS

BEGIN

...

END

GO

No comments:

Post a Comment