sql随机插入数据--记录
sql面试题中经常出现一张学生表,表字段有学生ID,学生课程,学生成绩
今天要实测,so,需要有数据,now,随机生成数据,,,
1 create table student 2 ( 3 id varchar(50), --编号 4 class varchar(50),--课程 5 soure int --成绩 6 ) 7 go 8 9 declare @i int 10 set @i = 0 11 12 while @i<30 13 begin 14 15 --插入数据 16 declare @r int 17 exec awf_RandInt 50,100,@r output 18 insert into student values(''+@i,'语文',@r) 19 20 --修改数据 21 exec awf_RandInt 0,30,@r output 22 update student set class = '数学' where id = @r+'' 23 24 --修改数据 25 exec awf_RandInt 0,30,@r output 26 update student set class = '英语' where id = @r+'' 27 28 29 set @i=@i+1 30 end 31 select * from student
随机整数实在园子里找得,贴出来
1 --生成随机整数 2 create procedure awf_RandInt 3 @min int, 4 @max int, 5 @result int output 6 as 7 begin 8 set @result= cast((rand()*(@max-@min)+@min) as int) 9 return @result 10 end