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;
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。