Reputation: 314
I am creating a desktop application which will test users knowledge of particular subject, by asking multiple choice questions. Each question contains unique question number, problem, four options, correct answer, topic and difficulty. I have a database of such question. For each user, i want to keep a track of questions he has attempted, so that i may provide him his progress analysis and also to provide better quality of question. How may I store required data for each user?
I already have a database of users details and one of questions in mySQL.
Upvotes: 0
Views: 263
Reputation: 611
You should have three tables:
The users table will have a primary key eg, PRIMARY KEY (userID)
The Questions table will also have a primary key. Finally the Scores table will have a primary key and two foreign keys referencing the users and questions tables eg.
PRIMARY KEY (scoreID),
FOREIGN KEY (userID) REFERENCES Users(userID),
FOREIGN KEY (questionID) REFERENCES Questions(questionID)
The primary key for the scores table cannot be a composite of the two foreign keys because a user may have many different scores for each question. The primary key has to be unique. Of course the scores table will have a score attribute(column) to store the scores for each time.
As for which data types to use, all you need is the int data type for primary keys and the score unless you want to use a more precise type like float for the score. I suggest you use varchar for things like user names.
Upvotes: 2