游标的使用

把一张表的 每行数据的 一个字段的值进行随机fetch

declare @tid int

declare topic_cur cursor for

select tid

from bbs_topics

open topic_cur

fetch next from topic_cur into @tid

while (@@fetch_status=0)

begin

UPDATE [dbo].[bbs_topics] SET iconid=CEILING(rand()*15) WHERE tid=@tid

fetch next from topic_cur into @tid

end

close topic_cur

deallocate topic_cur
相关文章
相关标签/搜索