我会尝试一些更简单的方法,然后一步一步规范化它。
Users 表不错
create table users (
userid int not null auto_increment primary key,
email varchar(100) not null,
password varchar(255) not null
);
问题表
我只是在问题表中标记谁提出了问题
create table questions (
questionid int not null auto_increment primary key,
question mediumtext or whatever,
userid int not null,
add fk here for userid
);
问题投票 - 多对多/联结表
create table question_votes (
question_votesid int not null auto_increment primary key,
questionid int not null,
voterid int not null,
votedate timestamp not null default current_timestamp,
score int not null,
add fk here for questionid and voterid
);
答案表
create table answers (
answerid int not null auto_increment primary key,
answer mediumtext or whatever,
questionid int not null,
userid int not null,
add fk here for questionid, userid
);
您可以选择创建只包含答案的答案和一个名为 question_answers 的连接表,其中包含 questionid、answerid 列。您也可以选择将 question_userid 和 answer_userid 放在此表中。阅读最后一段以自己获得答案。
答案投票表
create table answer_votes (
answer_votesid int not null auto_increment primary key,
answerid int not null,
voterid int not null,
votedate timestamp not null default current_timestamp,
score int not null,
add fk here for answerid and voterid
);
将一些虚拟数据放入其中,然后开始问自己一些问题——我需要从中得到什么样的信息。如果 X 发生了怎么办?当 X 发生时,这个模式可以适应我将来会被问到的答案吗?等等
当您在脑海中进行这些问答时,您会发现应该在哪里规范化以及规范化到什么程度。