getForeignKeys() as $fk) { ?> IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name='getName() ?>') ALTER TABLE getName() ?> DROP CONSTRAINT getName()?>; IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'getName() ?>') BEGIN DECLARE @reftable_ nvarchar(60), @constraintname_ nvarchar(60) DECLARE refcursor CURSOR FOR select reftables.name tablename, cons.name constraintname from sysobjects tables, sysobjects reftables, sysobjects cons, sysreferences ref where tables.id = ref.rkeyid and cons.id = ref.constid and reftables.id = ref.fkeyid and tables.name = 'getName() ?>' OPEN refcursor FETCH NEXT from refcursor into @reftable_, @constraintname_ while @@FETCH_STATUS = 0 BEGIN exec ('alter table '+@reftable_+' drop constraint '+@constraintname_) FETCH NEXT from refcursor into @reftable_, @constraintname_ END CLOSE refcursor DEALLOCATE refcursor DROP TABLE getName() ?> END