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

一个在线考试系统 表关系问题,欢迎高人指教!
自己理了理,总是搞不清,准备做这几张表
每次自动从题库随机抽题组成一张卷子,每张卷子20题选择,6道简答,选择题电脑批改,简答题老师给分

总觉得最后的试卷表很臃肿,但是又没有想到好方法去解决,我觉得在查询时是需要输出整张试卷的(包括学生答错的),不保存在一起会要查询多张表,有没有别的设计方法。

新手发言,大家请指教!
SQLServer?表?关系图

------解决方案--------------------
你这个试卷表是一个实实在在的表?还是select的结果?
如果是实实在在的表的话,那你的冗余字段太多了。
1.有了学生编号,其他的姓名等,直接按照编号在学生表中读。
2.每一道选择题,只要在1列中写入选择题编号,然后在题库表中读取全部内容。
3.得分新建一个表,存入该生的得分。
------解决方案--------------------
试卷头表
试卷明细表 每道题一条记录

学生答卷头表 每人每卷一条记录
学生答卷明细表 每道题一条记录

------解决方案--------------------
试卷头表 字段:试卷id,类型,什么年级,什么老师,满分多少,。。。。
试卷明细表 每道题一条记录 字段:试题id,所属试卷id,分类,序号,每题题目,分数,答案

学生表 学生id

学生答卷头表 每人每卷一条记录 字段:答卷id,学生id,试卷id,参与时间,总分,。。。
学生答卷明细表 每道题一条记录 字段:答卷明细id,答卷id,试题id,答题内容,得分,老师评点,。。。。

试卷相当于是树的模板(明细是题目)
答卷相当于是同一个树模板套出来的一个个实例树(每人一个实例,节点明细是答案)
------解决方案--------------------
题干、答案、试卷、答卷可以分开。


--==================试题===============
--题目主表
CREATE TABLE #Question
(
Id int primary key identity(1,1),
[Subject] int not null,--科目
Question nvarchar(max) not null,--题干
[Type] int not null --题目类型:0、选择题,1、简答题
)
--选择题扩展表
CREATE TABLE #OptionQuestion
(
Id int primary key identity(1,1),
QuestionId int not null,--Question表的主键
[Content] nvarchar(max) not null, --选择题的选择项
[Option] char(1) not null, --选项编号:A、B、C、D、E...
[IsSignle] char(1) default('Y') --是否单选:Y-单选,N-多选
)

--选择题的标准答案(如果是多选题,则该表中将存在多条记录)
CREATE TABLE #OptionStandard
(
Id int primary key identity(1,1),
QuestionId int not null,--Question表的主键
OptionId int not null --OptionQuestion表的主键
)

--==================试卷==================
--试卷主表
CREATE TABLE #Paper
(
Id int primary key identity(1,1),
[Subject] int not null,--科目
Scores decimal(5,1)--满分
)

--试卷题目
CREATE TABLE #PaperQuestion
(
Id int primary key identity(1,1),
PaperId int not null,--Paper主键
[Number] int not null,--题号
QuestionId int not null,--Question主键
Scores decimal(5,1) --本题满分
)

--==================答卷==================
--答卷主表
CREATE TABLE #Answer
(
Id int primary key identity(1,1),
StudentId char(10), --学号
PaperId int not null,--Paper主键
Scores decimal(5,1) --本卷最终得分
)

--答卷详细表
CREATE TABLE #AnswersDetail
(
Id int primary key identity(1,1),
AnswerId int not null,--Answer表主键
PaperQuestionId int not null,--PaperQuestion主键
Answer nvarchar(max),--答案(该题为简答题时即学生答案,为选择题时即为A、B、C、D...选项,多选题各选项间用,隔开)
Scores decimal(5,1) --本题最终得分
)