日期:2014-05-17  浏览次数:20478 次

关于sql随机抽取题目id跟题目TopicTypeId问题
先跟大家介绍几个表:
--科目类型
create table SubjectType
(
  SubjectTypeId int primary key identity(1,1),   --科目类型id
  SubjectTypeName nvarchar(20) not null,         --科目类型名称
)
insert into SubjectType values('c1交通')
insert into SubjectType values('C#')
insert into SubjectType values('java')
--题目类型
create table TopicType
(
    TopicTypeId int primary key identity(1,1),    --题目类型ID
    TopicTypeName nvarchar(2) not null,           --题目类型名称
)
insert into TopicType values('单选')
insert into TopicType values('多选')
--题目表
create table QuestionBank
(
   QuestionBankId int primary key identity(1,1),               --题库id
   SubjectTypeId int references SubjectType(SubjectTypeId),    --科目类型id
   TopicTypeId int references TopicType(TopicTypeId),          --题目类型id
   TopicName nvarchar(100) not null,                           --题目名称
   Fraction float not null,                                    --题目分数
)
--试卷表(存放考生考的试卷)
create table Exam
(
   ExamId int primary key identity(1,1),                             --试卷id
   UserNumber char(20) references UserDetails(UserNumber),           --考生编号(外键)
   ExamSexId int references ExamSex(ExamSexId),                      --做的是那套试卷(外键)
   IsSubmit bit not null,                                            --是否提交
)
我想在题目表中随机抽取题目,抽取题目需要条件是
--试卷id跟考生编号先写死吧
--抽取题目的条件,根据科目id,题目类型id(单选还是多选),抽取不能有重复项,然后添加到题目表中,
--需要存储过程写,最后带上解释说明,本人sql菜鸟,谢谢大家
------解决方案--------------------
元芳,CSDN新论坛上线!你怎么看?