usp_tmp_DropFK

Parameters

Parameter Parameter Type Mode Description
@TABLENAME nvarchar(max) IN

Definition

Copy

      create procedure usp_tmp_DropFK( @TABLENAME as nvarchar(max))
as
declare alters cursor local fast_forward for
    select 'alter table dbo.[' + o.name + '] drop constraint ' + k.name 
    from 
        sys.foreign_keys as k
    inner join 
        sys.objects as o on k.parent_object_id = o.object_id
    where 
        o.name = @TABLENAME
;
declare @stmt as nvarchar(max);
open alters;
fetch next from alters into @stmt;
while @@FETCH_STATUS = 0
begin
    exec(@stmt);
    fetch next from alters into @stmt;
end;
close alters;
deallocate alters;