Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C#
I am started doing a project :- Online Exam in ASP.NET with C#, database:- SQL Server

The exam consists of different sections such as Reasoning, Quantitative Aptitude & Numerical ability, English and Mathematics.
The exam is of objective type like fill in the blacks, option type and passage type.

The problem is how do I store passage type questions and answers in table??Because it will contain one long passage and based on that more than one questions will be asked with multiple choice options.


What I have tried:

The question table consist of the following columns:
Qid,Question,Option1,Option2,Option3,Option4,correctAnswer
Posted
Updated 23-Mar-16 8:34am

If I understand your problem, it is how to store the "passage" that precedes a group of questions.
If so, the way I'd do it would be to have an additional Passage table with Id (integer) and Text (varchar) columns; and have an additional column in the Question table that is the foreign key to the Passage table (probably nullable for the questions that are standalone).
 
Share this answer
 
v2
Responding to your comment to Solution 1 - If I was doing this I would probably have three tables, namely
* passage
* answer
* question

That way I can re-use (incorrect) answers for some of the question options - so I am only storing the text once. Every table should have its own Id column and the question table will need foreign keys to the other two. E.g.
SQL
create table passage
(
	passageId int identity(1,1),
	passage varchar(max)
)
create table answer
(
	answerId int identity(1,1),
	answerText varchar(max)
)
create table question
(
	id int identity(1,1),
	passage int,		-- set this up as a FK to table [passage]
	question varchar(max),
	option1 int,		-- set these up as a FKs to table [answer]
	option2 int,
	option3 int,
	option4 int,
	correct int
)

An example of how this could work:
SQL
insert into passage values
('This is a long passage for evaluation'),
('This is another long passage for evaluation')

insert into answer values
('An anwer that can be reused'),('Another answer'),
('And yet another one'),('and another answer'),
('the correct answer for Q1'),('the correct answer for Q2')

insert into question values
(1, 'Q1 text', 1,2,3,5,5),
(2, 'Q2 text', 3,4,5,6,6)
Note that I've re-used the text for answers 3 and 5 but only at the cost of storing an integer value.

Getting the data out will involve multiple joins e.g.
SQL
select p.passage, q.question, 
		a1.answerText as Option1, a2.answerText as Option2,
		a3.answerText as Option3, a4.answerText as Option4,
		c.answerId as Correct
from passage p
join question q on p.passageId = q.passage
join answer a1 on q.option1 = a1.answerId
join answer a2 on q.option2 = a2.answerId
join answer a3 on q.option3 = a3.answerId
join answer a4 on q.option4 = a4.answerId
join answer c on q.correct = c.answerId
(So you would probably want to put indexes on the Id columns on each table)

If you want to re-use the question text for different passages then you would need another table that links a question to a passage... this new table would contain a link to the question, all of the options foreign keys and the correct answer. The question table would then only contain its Id and text columns.
 
Share this answer
 
Comments
Member 12170781 28-Mar-16 9:58am    
Sorry for the late reply... As you know, the absence of a value (a null) in the foreign key is not allowed. some question may be from mathematics or GK .so this type of questions don't contain any passage then the 'question' table as you specified above will not work . Am I right?
CHill60 28-Mar-16 10:05am    
Yes you are right. However, the model will still work as long as you don't set up a foreign key constraint on the table - in other words you can still store passageIds on the Question table but without the constraint null values will be allowed. This you can interpret as "this question does not have an associated passage". Alternatively you could have a dummy (blank possibly) passage on the passage table and link all questions with no associated passage to that dummy entry. In this case you could use the FK constraint, but personally I don't like this method (just including it so you can see the option)
Member 12170781 28-Mar-16 11:40am    
that's why I am facing problem in creating database tables. My website is based on all online exam practice....for example let's consider MCA. For the admission into MCA there where many entrance exams such as NIMCET, MHT CET MCA, JNU MCA,etc. The exam paper is consist of sections such as Reasoning, English, Mathematics and Computer Concepts .Keeping all these things in mind I have to design tables according to it.. Now have a look at the tables I designed

1) user(UserId,FullName,UserName,Password,Email,DOR,LastLoginDate,ContactNo,Dob,SecQuestion, SecAnswer,Role)

2) Result(ResultId,ExamPaperId,UserId,NoOfCorrectAnswer,TimeTaken,Rank)

3) ExamPaper(ExamPperId,ExamId,TotalMarks,NegativeMark,PossitiveMark,TotalTime,NoOfQues)

4) Question(QuestionId,PassageId,Option1,Option2,Option3,Option4,CorrectAns,SectionId)

5)Passage(PassageId,Passage)

6) Course(CourseId,CourseName)

7) Exam(ExamId,ExamName,CourseId)

8) Section(SectionId,SectionName,ExamId)

Am I going right? I am still stuck in database design
CHill60 28-Mar-16 11:54am    
2. Result tabel - I personally would not store Rank on the table as it will change over time. Calculate it when it is required.
3) ExamPaper table - Not sure what the NegativeMark and PositiveMark columns are about - is this the right place for that?
NoOfQues should be the same as TotalMarks - OR, if different questions carry different marks then you will need to store that information
in the Question table.
Your design is certainly normalized - possibly one level too many but that depends on how "wordy" some of that text is.
For example the Exam and ExamPaper tables could be combined - judge this based on the actual data though.
I will sometimes revisit my design once I have some sample data in it - for example if I'm having to join to too many tables to get basic or common information then I will combine those tables at the cost of a level of normalization.
You are certainly going in the right direction though :)
Member 12170781 28-Mar-16 13:13pm    
I have made changes in the tables as you said....have a look over it:

1) User( UserId, FullName, UserName, Password, Email, DOR, ContactNo, DOB, SecQuestion, SecAnswer,Role )

2) Result( ResultId, ExamId, UserId, NoOfCorrectAnswer, TimeTaken )

3) Exam( ExamId, ExamName, CourseId, TotalMarks, NegativeMark, PossitiveMark, TotalTime, NoOfQues )

4) Question( QuestionId, PassageId, Question, Option1, Option2, Option3, Option4, CorrectAns, SectionId )

5)Passage( PassageId, Passage )

6) Course( CourseId, CourseName )

7) Section( SectionId, SectionName, ExamId )

If any further changes are required then please tell.

Different exams having different marking criteria... In MCA entrance exam each correct answer will carry 4 marks. Each wrong answer will carry 1 negative mark. Unanswered questions will carry zero marks.So the positive marks is the correct answer marks.
As there is no link between Question table and Passage table so how can I insert and retrieve data from Question and Passage table ?
If you're using a modern version of SQL you can use varchar(max)
 
Share this answer
 
Comments
Member 12170781 23-Mar-16 13:45pm    
I think you are not getting what I am trying to say........passage type question contain one long passage and based on that passage questions will be there with multiple choice option answers. The Question Table have only one question column...So my question is where do I store long passage and its related questions with answers? What will be the table design to store such things?. ...I am not asking any question related to datatype

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900