da-sztorc
1/19/2018 - 9:44 AM

Alter Stored Procedure Template

Template for altering and creating new stored procedures. The 'IF' statement with 'CREATE PROCEDURE' ensures that sp is created in case it's not present.

IF NOT EXISTS (SELECT TOP 1 NULL FROM sys.objects WHERE object_id = OBJECT_ID(N'[Schema].[Procedure]') AND type in (N'P', N'PC'))
BEGIN
    EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [Schema].[Procedure] AS'
END
GO

ALTER PROCEDURE [Schema].[Procedure]
(
  -- ARGUMENTS
  @Argument INT
)
AS
BEGIN
	
  -- PROCEDURE BODY
  SELECT 'Procedure body goes here'; 
	
END
GO