在sql server 2008中,将表Region_Majia中的数据随机更新到表Category_Info中。
代码如下:
Declare @i int Declare @id int,@name varchar(250) Set @i=1 --Select top 1 @id=userid,@name= username from region_majia order by newid() Select getdate() While @i<500 Begin Select top 1 @id=userid,@name= username from region_majia order by newid() -- Select @id,@name ; Update Category_Info set creatuserid =@id,creatusername=@name where id in (select top 10 id from category_info where creatuserid=0 and createtime>'2011-7-4' ) Set @i=@i+1; END