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