既然ChoiceId
已经确定了 a ,那么如果你想对你的数据进行完全规范化,你 QuestionId
可以摆脱table 。QuestionId
Answer
我会使用以下结构:
create table questions (
question_id number primary key,
question_text text
);
create table questions_choices (
question_id number references questions(question_id),
choice_number number,
choice_text text,
primary key(question_id, choice_number)
);
create table answers (
answer_id number primary key,
user_id number references users(user_id),
question_id number,
choice_number number,
foreign key (question_id, choice_number) references questions_choices(question_id, choice_number)
);
这与您所拥有的类似,但在questions_choices
桌子上没有代理键。