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;
SQL SERVER 使用游标删除所有主键
•
生活家
赞 (0)
免费测姻缘八字,免费生辰八字算命姻缘
上一篇
2022年3月21日
SQL SERVER 根据字段名称批量设置为主键
下一篇
2022年3月21日