把一張表的 每行數據的 一個字段的值進行隨機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