游标多参数循环操作,效率确实高了不少。
CREATE PROCEDURE p AS
declare @UserID int
declare @MinID int
declare @UserTEL varchar(20)
declare cur_getUserID cursor for
select main_id,tel,min(id) from tel group by tel,main_id having count(*)>1
--select main_id,tel,min(id) from tel where main_id=962192 and tel='15882188374' group by tel,main_id
open cur_getUserID
fetch next from cur_getUserID into @UserID,@UserTEL,@MinID
while(@@fetch_status = 0)
begin
delete from tel where main_id=@UserID and tel=@UserTEL and id<>@MinID
fetch next from cur_getUserID into @UserID,@UserTEL,@MinID
end
close cur_getUserID
deallocate cur_getUserID
GO