A good process for writing a Stored Procedure script

When writing a script for a single stored procedure, I feel it is good practice to write it with a section to remove the script if it exists first.
That way, you know that your procedure is set up and runs exactly as you intend.

Below is an example for such a script

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spf_MyStoredProc]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[spf_MyStoredProc]
GO

CREATE PROCEDURE [dbo].[spf_MyStoredProc]
(
	@MyParam INT
)
AS

/*
	CONTENT GOES HERE
*/

END

GO
Subscribe

0 comments