SQL SERVER 使用游标删除所有主键

declare @pk varchar(100);
declare @tbname varchar(100);
declare cursor1 cursor for
select sys2.name as tbname,sys1.name as pk from sysobjects sys1 join sysobjects sys2 on sys1.parent_obj = sys2.[id] where sys1.xtype=’pk’;
open cursor1
fetch next from cursor1 into @tbname,@pk
while @@fetch_status=0
begin
–exec(‘alter table ‘+@tbname+’ drop ‘+ @pk) –删除原主键
–print ‘alter table ‘+@tbname+’ drop ‘+ @pk   –打印
fetch next from cursor1 into @tbname,@pk
end
close cursor1 ;
deallocate cursor1;

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐