[英]Putting data in a normalized database
我会尝试一些更简单的方法,并将其一次标准化。
用户表好
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将来出现的问题? 等等
在脑海中进行这些问答时,您会发现应该在哪里进行标准化以及在多大程度上进行标准化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.