SQL实战笔记1

select P_CommunityID from T_Person group by P_CommunityID
//创建游标
declare sc cursor scroll for select P_CommunityID from T_Person group by P_CommunityID
open sc
fetch first from sc
close sc
deallocate sc
//使用游标
declare @i int
fetch first from sc into @i
while @i!=541
begin
insert into ff
select TOP 76 * from T_Person where P_CommunityID=@i
fetch next from sc into @i
end
insert into ff
select top 76 * from T_Person where P_CommunityID=541
//随机删除
 delete from [YLBX兰考].[dbo].[ff] where PersonID in(SELECT top 195 PersonID FROM [YLBX兰考].[dbo].[ff] order by newid())

原文地址:https://www.cnblogs.com/lvfeilong/p/gfdgfdgfdg.html