260.删除数据库中的所有外键约束

63 阅读1分钟
--删除数据库中的所有外键约束

declare @s varchar(8000)
declare tb cursor local for
select s='alter table ['+object_name(parent_obj)+'] drop constraint ['+name+']' 
from sysobjects where xtype='F'

open tb 
fetch next from tb into @s
while @@fetch_status=0
begin
	exec(@s)
	fetch next from tb into @s
end
close tb
deallocate tb