gpt4 book ai didi

php - 将数据放入规范化数据库中

转载 作者:行者123 更新时间:2023-11-29 07:27:16 25 4
gpt4 key购买 nike

我正在构建一个数据库系统,用户可以对他们自己创建的问题进行投票。我正在努力解决的是正确填充数据库,特别是因为我尝试对其进行规范化,但这让我非常困惑!我对 SQL 和 MySQLi 非常陌生。

在下面的数据库中,当某人在我的网页上创建个人资料时,我如何最好地输入用户信息,然后当我想要将他们的 UserID 与 QuestionID 和 Up- 或他们投了反对票?

Database system for voting, users and question.

我正在寻求有关数据库设计的帮助,但特别是有关将数据放入数据库并将其“捆绑”在一起的问题的帮助。

最佳答案

我会尝试一些更简单的方法,并一次一步地将其规范化。

用户表很好

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 发生时,这个模式可以适应我将来会被问到的答案吗?等等

当你在脑海中思考这些问答时,你会发现你应该在哪里正常化以及正常化到什么程度。

关于php - 将数据放入规范化数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34121465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com