我可以为社交网站中的每个用户创建每个表吗?
我正在创建一个功能类似于 Facebook 的社交网站。 我想从数据库的架构设计开始。 我的想法是为注册到我们网站的每个用户创建每个表..我做对了吗?
如果一百万个用户注册到我的网站,就会创建一百万个表。如何继续优化这个?请给我建议克服这个问题的技术,一些参考资料或书籍来了解这些概念将会非常有用。
提前致谢。
I'm creating a social networking site with features similar to Facebook.
I want to start with schema design for my database.
What i thought was to create each table for each user who registers to our site.. am i doing right?
If a million users register to my site, a million tables will be created. how to go on about optimizing this? Please do suggest me techniques to overcome this and some references or books to learn about such concepts will be vry useful..
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是您想要的方式。
您想要做的是有一个表(可能称为
'users'
),其中包含每个注册用户的一行。为每个用户创建一个新表完全毫无意义,并且会导致糟糕性能。也许是这样的:
然后,当用户注册时,只需将他们提供的信息作为新行插入到
users
表中。This is not the way you want to do it.
What you want to do is have a table (perhaps called
'users'
) that contains one row for each user that registers. Creating a new table for each user is completely pointless and would cause terrible performance.Maybe something like this:
Then when a user registers, simply insert the information they provide into the
users
table as a new row.那将是巨大的杀伤力。您可能应该阅读数据库设计(从规范化开始,但不要过度)。然后写下你要为每个用户保存的内容,并思考如何保存而不保存数据双重。
但我很确定每个用户一个表不是一个选项。
That would be massive overkill. You should probably read up on database design (start with normalisation, but don't overdo it). Then write down what you want to save for each user, and think about how to save it without saving data double.
But I'm pretty sure a table-per-user is not an option for this.
您一定对数据库、表,字段(或列)、记录(或行)。
NAME
、SURNAME
、AGE
等。这些都是用户拥有的功能。{NAME:"John", SURNAME:"Smith", AGE:"32"}
。在您的示例中,我可以肯定地告诉您,您只需要一个数据库。您想要存储许多用户的信息,因此您需要一个名为
USER
的表。您需要存储用户的特征,例如:名字、姓氏、年龄、地址等,然后您需要在此表中创建相应字段:NAME
、SURNAME
、AGE
、ADDRESS
等。然后您需要将数据作为记录插入数据库中>。这将是您要存储的每个用户的一条记录。You must be confusing the meaning of the words database, table, field (or column), record (or row).
NAME
,SURNAME
,AGE
, etc. These are all features that a user has.{NAME:"John", SURNAME:"Smith", AGE:"32"}
.In your example, I can tell you for sure that you only need one database. You want to store information for many users, so you need one table called
USER
. You will need to store features to your users, like: name, surname, age, address, etc., then you will need to create the respective fields in this table:NAME
,SURNAME
,AGE
,ADDRESS
, etc. Then you will need to insert your data in the database as records. It will be one record per user you want to store.