I have some table:
- Course: contain info about course, one course
has manytopics. - Topic: contain info about topic, one topic
belongs toone course and one topichas manyquestions. - Question: contain info about question, one question
belongs toone topic. - GeneralExam: Contain info about the exam of a course, one general exam
belongs toone course. - GeneralQuestion: Contain set questions of General Exam.
This is columns of two table:
- GeneralExam: name, description, semester, duration, user_id, course_id, used (boolean), number_question
- GeneralQuestion: general_exam_id, question_id
The questions will be get for GeneralExam is random. It means I will get random questions depend on specific number of question of each topic.
Now I want to know specific information of an general exam, like the number of questions of each topic in course which was made a general exam. Currently, I think I will create a new table to store that info, something like:
- New table: general_exam_id, topic_id, number_question
But I don’t know if this is the best way to do it, or maybe in this case, has other ways or patterns to solve. Because If I create that New table, when I make a change in GeneralExam table(ex: change set questions), I will need to update 3 table: GeneralExam, GeneralQuestion, New table. I don’t sure it is the good way.
So I want to ask, should I create new table to store that information (number of questions of each topic in course of a general exam),
Or should I need to make some changes in table GeneralQuestion for store info of general exam better, and what changes I should do? Thanks for any suggestions and advices.
We are trying to say, that is not required to create a new extra table. You want to manage your schema efficiently with mimimal touches to tables.
Design Rules:
One should not confuse the numbered topics in a particular course book to Topic table’s ID numbers. Course doesn’t necessarily have to be belonged to an Exam. It’s the Exam who must belong to a Course. You have gotten your design so far correct. I assume you are storing all Questions for an Exam in GeneralQuestion table which acts like sort of a question bank of past Exams (including the schedule Exam in the near future which only gives access to the Exam moderators).
Makes more sense to rename your GeneralQuestions table into ExamsQuestions. With this bank your design makes two virtual question types: Exam questions from the bank and questions from Question table where Exam questions are referencing to your Question table. So that gives your the required referencial key to Exam question bank. In my opinion it is a history table. It seems like, your final table that you are not sure should ideally be just a stored query providing real time data.
Main question : Are you planning to store each past/scheduled-future Exam’s questions? You say Yes. Hence,
Date becomes very crucial column in your Exam table according to the design I have provided. You need both Date & Course ID in Exam table.
Following is how I would suggest the table schema.
tblCourse
ID, Course
tblTopic : Although ID is indexing, the CID is what recognizes the Topic’s Parent (the Course)
ID, CID, Topic
tblQuestion : Although ID is indexing, the TID is what recognizes the Question’s Parent (the topic)
ID, TID, Question
tblExam : Although ID is indexing, the CID is what recognizes the Question’s Parent (the course)
tblExamsQuestions : Foreign Keys : Exam ID, Question ID
ID, QID
Application:
Somebody wants to get last year’s Exam Questions for 1st Year Maths Course. How do you query that? If Exam ID is are on auto increment then it’s very hard to know what which id is what exam. So here you could be able to search questiosn for a particular course exam only with course id and date the exam held. That should do the job -> Unless same course exams held multiple times on the same day. Then you can save your data by Time as well. You can remove Date, Time as long as you change your Exam table design to query by Exam ID where the ID is a proper exam ID not just 1, 2, 3, …
Course ID = m122
Date = Last Year/Month/Date
These are the most logical/important details which will work as a COMPOSITE SEARCH KEY you need to find the Exam ID from Exam table and use that in ExamsQuestions bank to pull the Exam questions.
By the way since you are choosing questions randomly for an Exam – I would be so worried that if I have to take that Exam. Because the risk of getting all questions from one topic is pretty wide. Anyway that’s a side issue which I hope you have a unbiased yet FAIR mechanism to generate Exam from all topics for a course 😉
Let me if you have further doubts. Anyone please throw some light to improve ideas for better solutions.
PS: Sorry for the late reply.