Skip to content

Instantly share code, notes, and snippets.

@Novakov
Created September 12, 2012 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Novakov/3705522 to your computer and use it in GitHub Desktop.
Save Novakov/3705522 to your computer and use it in GitHub Desktop.
if exists(select * from sys.objects where object_id = OBJECT_ID(N'dbo.sp_drop') and type in (N'P'))
DROP PROCEDURE sp_drop;
GO
CREATE PROCEDURE sp_drop
@type nvarchar(2),
@name nvarchar(200)
AS
BEGIN
set nocount on;
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(@name) AND type in (@type))
BEGIN
declare @t nvarchar(20)
if @type = N'U'
set @t = N'table'
else if @type = 'V'
set @t = N'view'
else if @type = N'P'
set @t = N'procedure';
declare @sql nvarchar(200)
set @sql = N'drop ' + @t + N' ' + @name
exec sp_executesql @sql
END
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment