create table #t (keyId int identity,name varchar(200),tbname varchar(200))

insert into #t (name,tbName) 
select a.name,b.name from sys.foreign_keys a 
left join sysobjects b on a.parent_object_id = b.id 
declare @i int,@imax int,@name varchar(200) ,@tbName varchar(200)

select @i=MIN(keyId) from #t 
select @imax=MAX(keyid) from #t

while @i<=@imax
begin
set @name='' 
set @tbName =''
select @name =name,@tbName=tbname from #t where keyId=@i
--print @name 
--print @tbName 

print(' ALTER TABLE ['+@tbname +'] DROP CONSTRAINT ['+@name+']')
exec(' ALTER TABLE ['+@tbname +'] DROP CONSTRAINT ['+@name+']')

set @i=@i+1
end


truncate table #t 
drop table #t

相关文章:

  • 2019-06-21
  • 2018-08-27
  • 2020-11-08
  • 2018-03-10
  • 2019-10-31
  • 2021-10-22
  • 2018-07-20
  • 2019-09-02
猜你喜欢
  • 2018-08-23
  • 2019-02-21
  • 2018-10-12
  • 2019-03-16
  • 2020-02-27
  • 2019-02-23
  • 2018-11-14
  • 2019-09-26
相关资源
相似解决方案