I've recently started writing my own scripts to create a database instead of using EM. I quickly tired of copying and pasting the typical if exists then drop statements, so I created this procedure to save me some time.I know it doesn't take into account all of the possible data types, and I knowthat I'm not suppossed to query sysobjects directly, but it gets the job done for me. If you'd like to refactor it, please do./**********************************************************************procDropConstraint - This procedure simplifies dropping a constraint from the database. sysDropObject 'FK_NodeAudit_Node' Examples: EXEC sysDropObject 'FK_Node_Document' EXEC sysDropObject 'Document' EXEC sysDropObject 'Node'**********************************************************************/-- CREATE PROCEDURE sysDropObject @Name varchar(100)ASDECLARE @xtype nvarchar(2), @parentxtype nvarchar(2), @parentname nvarchar(100), @sql nvarchar(200)SELECT @xtype = child.xtype, @parentxtype = parent.xtype, @parentname = parent.nameFROM dbo.sysobjects child left outer join dbo.sysobjects parent on child.parent_obj = parent.idWHERE child.name = @Name AND child.xtype NOT IN ('S','D') --system tables and extended properties AND NOT (child.xtype = 'P' and LEFT(child.name, 3) = 'dt_') --local system proc AND NOT (child.xtype = 'V' and LEFT(child.name, 3) = 'sys') --local system viewsIF @xtype is null GOTO _NothingToDoHereIF @xtype IN ('F','PK','UQ') BEGIN SET @sql = N'ALTER TABLE [' + @parentname + '] DROP CONSTRAINT [' + @Name + ']' GOTO _ExecSql ENDIF @xtype = 'P' BEGIN SET @sql = N'DROP PROCEDURE [' + @Name + ']' GOTO _ExecSql ENDIF @xtype = 'U' BEGIN SET @sql = N'DROP TABLE [' + @Name + ']' GOTO _ExecSql END_Fail: RAISERROR( 'Unhandled xtype ''%s'' for %s', 16, 1, @xtype, @Name ) RETURN 1_ExecSql: EXEC sp_executesql @sql PRINT 'sysDropObject: executed - ' + @sql RETURN 0_NothingToDoHere: PRINT 'sysDropObject: attempted to drop ' + @Name + ', but it does not exist to be dropped.' RETURN 0GO