You are here: Home > Technical Articles > MS SQL Server - Drop Stored Procedure If It Exists

MS Sql Server - Drop Stored Procedure If It Exists


SQL script for dropping a stored procedure if it exists in the database.

-- SQL Server 2005 Script
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'p_contact_us_save' AND type = 'P')
BEGIN
    DROP PROCEDURE p_contact_us_save
END
GO

-- SQL Server 2000 Script
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[p_contact_us_save]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
    DROP PROCEDURE [dbo].[p_contact_us_save]   
END
GO


Published On: 02 Aug 2009