试题库 T_Questions 包括, 题号(自增长)、题目内容、答案 、题目类型 。
ques_NO ques_content answer type
2 1+1=? 2 A
5 2+2=? 4 B
6 ... . .
8 ... . .
10 ... . .根据 ,出题类型 ,随机 抽题,在存储过程里处理 ,声明了 表变量 存储 ,
while(...)-- 循环 试题 类型
declare @tempQT table(id int identity(1,1), ques_NO int) --表变量:加 自动序号列
insert into @tempQT select ques_NO from T_Questions where type = @typeiddeclare @countQuesNum int -- 产生随机 乘数
set @countQuesNum = ( select count(*) from @tempQT)declare @l int
set @l = 0 ;
while(@l < @number)-- 循环 产生 多个题目
begin
declare @rand_temp int -- 随机数 临时ID值
declare @rand_Num int -- 真正的 随机 题号
set @rand_temp = ( select rand()*(@countQuesNum-1) + 1 ) -- 产生随机题号
set @rand_Num = (select qaid from @tempQT where id = @rand_temp
set @quesStrings = (select stuff(@quesStrings,@rand_Num,1,'1'))-- 进一步处理题目
set @l = @l + 1 ;
end
... ...
这样后 ,表变量 不是 每个类别新建的ID ,而是在原 数据行的 基础上 自增 。想 把它 删除掉
若 用临时表 也是 不行的 ,提示:'无法使用 SELECT INTO 语句将标识列添加到表 '#tempQT',该表的列 'quest_NO' 已继承了标识属性。'表变量 在批处理 结束后,由系统 自动回收 ,现在我想 ,每次 while 结束后 ,手动 清除 ??? 大侠帮忙 !!!
ques_NO ques_content answer type
2 1+1=? 2 A
5 2+2=? 4 B
6 ... . .
8 ... . .
10 ... . .根据 ,出题类型 ,随机 抽题,在存储过程里处理 ,声明了 表变量 存储 ,
while(...)-- 循环 试题 类型
declare @tempQT table(id int identity(1,1), ques_NO int) --表变量:加 自动序号列
insert into @tempQT select ques_NO from T_Questions where type = @typeiddeclare @countQuesNum int -- 产生随机 乘数
set @countQuesNum = ( select count(*) from @tempQT)declare @l int
set @l = 0 ;
while(@l < @number)-- 循环 产生 多个题目
begin
declare @rand_temp int -- 随机数 临时ID值
declare @rand_Num int -- 真正的 随机 题号
set @rand_temp = ( select rand()*(@countQuesNum-1) + 1 ) -- 产生随机题号
set @rand_Num = (select qaid from @tempQT where id = @rand_temp
set @quesStrings = (select stuff(@quesStrings,@rand_Num,1,'1'))-- 进一步处理题目
set @l = @l + 1 ;
end
... ...
这样后 ,表变量 不是 每个类别新建的ID ,而是在原 数据行的 基础上 自增 。想 把它 删除掉
若 用临时表 也是 不行的 ,提示:'无法使用 SELECT INTO 语句将标识列添加到表 '#tempQT',该表的列 'quest_NO' 已继承了标识属性。'表变量 在批处理 结束后,由系统 自动回收 ,现在我想 ,每次 while 结束后 ,手动 清除 ??? 大侠帮忙 !!!
DELETE @TABLE
检查指定表的当前标识值,如有必要,还对标识值进行更正。语法
DBCC CHECKIDENT
( 'table_name'
[ , { NORESEED
| { RESEED [ , new_reseed_value ] }
}
]
)
原来是这东西,呵呵
检查指定表的当前标识值,如有必要,还对标识值进行更正。语法
DBCC CHECKIDENT
( 'table_name'
[ , { NORESEED
| { RESEED [ , new_reseed_value ] }
}
]
)参数
'table_name'是要对其当前标识值进行检查的表名。表名必须符合标识符规则。有关更多信息,请参见使用标识符。指定的表必须包含标识列。NORESEED指定不应更正当前标识值。RESEED指定应该更正当前标识值。new_reseed_value是在标识列中重新赋值时要使用的值参考联机丛书
end
delete @tempQT ;
DBCC CHECKIDENT('@tempQT',reseed,1)
set @k = @k + 1 ; 在第二个 循环 结束后 ,加的 。怎么 访问 不到 呢 ?
消息 2501,级别 16,状态 45,过程 pro_ProductPaper,第 88 行
找不到名为 "@tempQT" 的表或对象。请检查系统目录。
select * from tb where type='A' order by newid()也可以随机抽题目的