use School --指定数据库 declare @min_id int --声明整数变量@x set @min_id=(select MIN(Id) from Students) --给变量@x赋初值为当前最小的Id值 while @min_id>0 begin update Students set Age=ROUND(RAND()*100,0) where Id=@min_id --round()四舍五入把原值转化为指定小数位数 --rand()取得是随机数 默认范围为(0·1) rand()*100范围是0~100 select @min_id=(select MIN(Id) from Students where Id>@min_id) end