需要建议:mysql数据库结构

发布于 2024-10-04 03:43:56 字数 1109 浏览 1 评论 0原文

另一个数据库结构问题,希望你们不介意:

我在我的网站上进行了这个视频测验,流程如下:

  1. 观看者将观看一个视频
  2. ,该视频附加了一个问题
  3. ,并且还有两个问题,其中一个是错误的,当然另一个是正确的,

到目前为止我已经为此想出了两种数据库设计,

第一个是:

table: video 
fields: id, filename, type, size, created

table: question 
fields: id, question, right_answer, wrong_answer, video_id

第二个,我将每个不同表上的问题和答案分开,

table: video 
fields: id, filename, type, size, created

table: question 
fields: id, video_id, question

table: answer
fields: id, answer, video_id, status

答案表中的状态字段是为了表明答案是正确还是错误,可能使用tinyint通过0和1的值,

你们会推荐我哪一个作为更好的方法以及为什么,并且由于我不太了解数据库规范化,有没有简单的方法理解文章,以便我可以提高我的知识,任何帮助将不胜感激,谢谢

问候

更新:

谢谢大家为我的数据库设计指出了更好的方法,因为每个人都建议我应该使用 boolean 或 bit 作为字段类型,并且我总是使用tinyint来表示之前这样的字段:p,所以我搜索了一个解决方案,关于我应该在 mysql 中使用什么类型来表示 boolean,我偶然发现了这个 使用哪种 MySQL 数据类型来存储来自/到的布尔值PHP?并且根据该问题的答案我应该使用tinyint(1),所以我想可以肯定地说我现在将继续使用tinyint:p

再次感谢大家

another database structuring question, hope you guys dont mind :D

i am having this video quiz on my web, with this kind of flow:

  1. the viewer will watch a video
  2. that particular video has a question attached to it
  3. and it also has 2 questions, one of them is false and of course the other is true

so far i have figured out two database design for this

the 1st one is:

table: video 
fields: id, filename, type, size, created

table: question 
fields: id, question, right_answer, wrong_answer, video_id

the 2nd one, i am separating the question and the answer on each different tables

table: video 
fields: id, filename, type, size, created

table: question 
fields: id, video_id, question

table: answer
fields: id, answer, video_id, status

the status field in answer's table is to indicate whether the answer is right or wrong, probably using tinyint by the value of 0 and 1

which one would you guys recommend me as a better approach and why, and since i don't really understand database normalization, is there any easy to understand article so that i can improve my knowledge regarding that, any help would be much appreciated, thanks

Regards

Update:

thank you everybody for pointing out a better approach for my database design, since everyone is suggesting that i should use boolean or bit as field type and i always use tinyint for fields like this before :p, so i search over for a solution on what type should i use in mysql to represent boolean, and i stumble upon this Which MySQL Datatype to use for storing boolean values from/to PHP? and according to the answer of that question i should use tinyint(1), so i guess it's safe to say that i will keep using tinyint for now :p

thanks again everyone

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳若烟 2024-10-11 03:43:56

原谅 ASCII,我建议如下:

VIDEO                Question             Answer
|- id       1--.     |- id       1--.     |- id
|- filename     '--* |- video_id     '--* |- question_id
|- type              '- question          |- answer
|- size                                   '- correct (bit, not tinyint)
'- Created

这使您可以自由地在视频上添加多个问题,并为每个问题添加多个答案。另外,我建议使用一点(不是tinyint)来标记“正确”答案。我还尝试展示在这种情况下按键如何对齐。

Forgiving the ASCII, I recommend the following:

VIDEO                Question             Answer
|- id       1--.     |- id       1--.     |- id
|- filename     '--* |- video_id     '--* |- question_id
|- type              '- question          |- answer
|- size                                   '- correct (bit, not tinyint)
'- Created

That gives you the freedom of adding multiple questions on a video, and multiple answers to each question. Also, i suggest using a bit (not a tinyint) to flag the "Correct" answer. I also tried to show how the keys would align in this scenario.

叹沉浮 2024-10-11 03:43:56

直觉上,我会选择第一个解决方案,因为无论如何您很可能需要同时检索两个问题。

顺便说一句,如果您选择第二个选项,那么我建议您对“status”字段使用布尔值,而不是tinyint。

Intuitively, I'd go for the first solution, as you will most likely need to retrieve both questions at the same time anyway.

By the way, if you go for the second option, then I would advise you to use a boolean value for the "status" field, instead of a tinyint.

南…巷孤猫 2024-10-11 03:43:56

如果您打算添加更多答案,则采用第二种方式,否则使用第一种方式。

If you plan to add more answers, then take the second way, otherwise use the first one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文