Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Drop Procedure If It Exists
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

80 Posts

Posted - 07/31/2008 :  17:21:57  Show Profile  Reply with Quote
--Drops a Procedure if it exists and prints a message with the result.
CREATE PROCEDURE [dbo].[Utils_DropProcedure]
@ProcedureName varchar(128)
Declare @SQL varchar(4000)
set @SQL = 'IF (EXISTS (SELECT * FROM dbo.sysobjects '
+ ' WHERE id = OBJECT_ID('''
+ @ProcedureName + ''') AND OBJECTPROPERTY(id,''IsProcedure'') = 1))'
+ 'BEGIN PRINT ''Dropping the Procedure:'' PRINT '''
+ @ProcedureName + ''' DROP PROCEDURE ['
+ @ProcedureName + '] END ELSE BEGIN PRINT ''Procedure Not Found:'''
+ 'Print ''' + @ProcedureName + ''' END'


  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000