Drop Stored Procedure if exist in SQL Server

Its very frequent that we need to check whether particular store procedure exist in database or not?

If stored procedure exist then delete the stored procedure, otherwise we have to toggle between Create Procedure and Alter Procedure.

Below is the SQL to delete the stored procedure if exist.

IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[SPNAME]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)




Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.