declare @tab varchar(50),@forkey varchar(50),@sql varchar(200),@int int,@i int

select @int=count(*) from sys.foreign_keys
set @i=1
while @i <= @int
begin
select top 1 @tab=o.name,@forkey=fk.name from sys.foreign_keys fk
JOIN sys.all_objects o ON (fk.parent_object_id=o.object_id)
order by o.name

set @sql='alter table ' + @tab + ' drop constraint ' + @forkey
select @sql
exec(@sql);
set @i = @i + 1
end

posted on 2012-01-04 14:53  花祭果凛  阅读(292)  评论(0编辑  收藏  举报