游标的使用

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

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

 

posted @ 2014-08-26 14:39  递龟  阅读(205)  评论(0编辑  收藏  举报