SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

gregoryagu
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)
)
AS
BEGIN
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'


EXECUTE (@SQL)
END

GO
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000