I will apologise now coming from a c++ opp design pattern
for the example three table database (non-Key fields omitted) is it possible sane to do the following Responses table
FOREIGN KEY(question_number) REFERENCES Questions(assessment_ID,question_number)
CREATE TABLE `Attempt` (
`attempt_ID` INTEGER PRIMARY KEY AUTOINCREMENT,
`username` TEXT NOT NULL,
`assessment_ID` INTEGER NOT NULL,
`timestamp` INTEGER NOT NULL,
FOREIGN KEY(`username`) REFERENCES Students ( username ),
FOREIGN KEY(`assessment_ID`) REFERENCES Assessments ( assessment_ID )
);
CREATE TABLE `Questions` (
`assessment_ID` INTEGER NOT NULL,
`question_number` INTEGER NOT NULL,
PRIMARY KEY(assessment_ID,question_number)
);
CREATE TABLE "Responses" (
`attempt_ID` INTEGER,
`question_number` INTEGER,
PRIMARY KEY(attempt_ID,question_number),
FOREIGN KEY(`attempt_ID`) REFERENCES Attempt ( attempt_ID )
);
The obvious solution is to include the assessment_ID in every question.row but if we already know the attempt_ID then we can lookup the assessment ID ?
Sub_Reference maybe ?
Aucun commentaire:
Enregistrer un commentaire