需要建议:mysql数据库结构
另一个数据库结构问题,希望你们不介意:
我在我的网站上进行了这个视频测验,流程如下:
- 观看者将观看一个视频
- ,该视频附加了一个问题
- ,并且还有两个问题,其中一个是错误的,当然另一个是正确的,
到目前为止我已经为此想出了两种数据库设计,
第一个是:
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:
- the viewer will watch a video
- that particular video has a question attached to it
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
原谅 ASCII,我建议如下:
这使您可以自由地在视频上添加多个问题,并为每个问题添加多个答案。另外,我建议使用一点(不是tinyint)来标记“正确”答案。我还尝试展示在这种情况下按键如何对齐。
Forgiving the ASCII, I recommend the following:
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.
直觉上,我会选择第一个解决方案,因为无论如何您很可能需要同时检索两个问题。
顺便说一句,如果您选择第二个选项,那么我建议您对“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.
如果您打算添加更多答案,则采用第二种方式,否则使用第一种方式。
If you plan to add more answers, then take the second way, otherwise use the first one.