简体   繁体   English

我应该如何设计这个数据库?

[英]How should I design this database?

Let's say I have 10 millions of product names, eg iPhone 6. For each product name, there may be multiple comments or reviews. 假设我有1000万个产品名称,例如iPhone6。对于每个产品名称,可能会有多个评论或评论。 When users search for a product name, it will display all comments for it. 用户搜索产品名称时,它将显示该产品的所有注释。 Should I use two tables to fulfill this requirement? 我应该使用两个表来满足此要求吗?

Table one: ProductName, with only one column, "prodName" Table two: Comments, with only one column, "comments" 表一:ProductName,仅一栏,“ prodName”表二:注释,仅一栏,“评论”

What's the relationship between the two? 两者之间是什么关系? I am new to database design, and will use MySql to do this, Hibernate in Java. 我是数据库设计的新手,它将在Java中使用MySql进行Hibernate。 I am thinking to make it as simple as possible, to start with. 首先,我正在考虑使其尽可能简单。

Thank you. 谢谢。

If you were to keep a single table for product information and comments for that product you would need to duplicate the product name for each comment made. 如果要为产品信息和注释保留一个表格,则需要为每个注释重复产品名称。 When having to store 10 million products that can be very dangerous. 当必须存储1000万种产品时,这将非常危险。

Another issue is table extensibility. 另一个问题是表的可扩展性。 Lets say you want to add another info, apart from the name, that is closely linked to the product ie stock. 假设您要添加除名称之外的另一条信息,该信息与产品(即库存)紧密相关。 You do not want to have that info in your table duplicated based on the comments being made for that product. 您不希望根据针对该产品所做的评论在表中重复该信息。

To avoid these kind of issues you could consider an architecture similar to this: http://sqlfiddle.com/#!9/b50a8/2 , link your tables with their keys and avoid information duplication. 为避免此类问题,您可以考虑使用类似于以下的体系结构: http : //sqlfiddle.com/#!9/b50a8/2 ,将表与其键关联,并避免信息重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM