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)

BEGIN

DROP PROCEDURE dbo.SPNAME

END

Posted

in

,

by

Tags:


Related Posts

Comments

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading