Thursday, September 6, 2012

Create a Stored Procedure if don't exists

There are couple of processes around that:
1. Dropping the stored procedure if it exists and recreating
2. Creating the stored if it don't exists , otherwise altering it

Approach 1 :

Approach 2:
if object_id('[AddArqueEvalConfig]') is null
    exec ('create procedure dbo.[AddArqueEvalConfig] as select 1')
go
    alter procedure [dbo].[AddArqueEvalConfig] 

    @CustomerName_ nvarchar(max),
--…..other sql parameters
    
    AS
BEGIN

--Your sql statements here

END


Wednesday, August 22, 2012

Stored Procedure good practices

In every stored proc check if it already exists:

IF OBJECT_ID('MySproc') IS NOT NULL 
DROP PROC MySproc 
GO 
 
CREATE PROC MySproc 
AS 
BEGIN 
    ... 
END