SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON GO if exists (select * from sysobjects where id = object_id(N'[dbo].[sp_drop_constraints]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_drop_constraints] GO create proc sp_drop_constraints @tablename sysname as -- name: sp_drop_constraints -- author: douglas bass -- date: 06/19/2000 -- sp_drop_constraints will drop all constraints on the specified table, -- including CHECK, FOREIGN KEY, PRIMARY KEY, UNIQUE, and DEFAULT constraints. -- Compile it in your master database and use it from any user database. set nocount on declare @constname sysname, @cmd varchar(1024) declare curs_constraints cursor for select name from sysobjects where xtype in ('C', 'F', 'PK', 'UQ', 'D') and (status & 64) = 0 and parent_obj = object_id(@tablename) open curs_constraints fetch next from curs_constraints into @constname while (@@fetch_status = 0) begin select @cmd = 'ALTER TABLE ' + @tablename + ' DROP CONSTRAINT ' + @constname exec(@cmd) fetch next from curs_constraints into @constname end close curs_constraints deallocate curs_constraints return 0 GO SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON GO