|
在查询分析器中编写存储过程input5,实现此功能.
前提:
设数据库中表结构如下:
编号sid int
姓名sname char 10
性别sex 2
科目item 14
分数score int
代码:
create proc input5
as
begin
declare @i int
declare @f float
declare @x int
declare @sname char(10)
declare @sex char(2)
declare @item char(14)
declare @score int
set @i=1
while(@i<=100)
begin
set @sname='LI'+STR(@i,3,0)
set @f=RAND(@i)
set @sex=RIGHT(STR(@f,7,5),1)
set @score=CAST(RIGHT(STR(@f,7,5),2) AS int)
if @sex='1' or @sex='2' or @sex='3'
begin
set @sex='y'
set @item='shuxue'
end
else
begin
set @sex='n'
set @item='yuwen'
end
insert into test1(sid,sname,sex,item,score) values(@i,@sname,@sex,@item,@score)
set @i=@i+1
end
end
执行:
exec input5 |
|