使用游标在存储过程中循环遍历数据
CREATE PROCEDURE updatecount AS
DECLARE @flashID int
DECLARE favCounts CURSOR LOCAL SCROLL FOR
SELECT flashID FROM flashs_Favorites
OPEN favCounts
FETCH NEXT FROM favCounts INTO @flashID
WHILE @@FETCH_STATUS = 0
BEGIN
update flashs_flashs set favCount=favcount + 1 where flashID=@flashID
FETCH NEXT FROM favCounts INTO @flashID
END
CLOSE favCounts
DEALLOCATE favCounts
GO
DECLARE @flashID int
DECLARE favCounts CURSOR LOCAL SCROLL FOR
SELECT flashID FROM flashs_Favorites
OPEN favCounts
FETCH NEXT FROM favCounts INTO @flashID
WHILE @@FETCH_STATUS = 0
BEGIN
update flashs_flashs set favCount=favcount + 1 where flashID=@flashID
FETCH NEXT FROM favCounts INTO @flashID
END
CLOSE favCounts
DEALLOCATE favCounts
GO