我可以为社交网站中的每个用户创建每个表吗?

发布于 2024-10-15 12:18:30 字数 180 浏览 2 评论 0原文

我正在创建一个功能类似于 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 技术交流群。

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

发布评论

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

评论(3

陪你到最终 2024-10-22 12:18:30

这不是您想要的方式。

您想要做的是有一个表(可能称为'users'),其中包含每个注册用户的一行。为每个用户创建一个新表完全毫无意义,并且会导致糟糕性能。

也许是这样的:

 TABLE users
   - username AS VARCHAR(255)
   - password AS VARCHAR(255) (use a hashed password, of course)
   - ...

然后,当用户注册时,只需将他们提供的信息作为新行插入到 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:

 TABLE users
   - username AS VARCHAR(255)
   - password AS VARCHAR(255) (use a hashed password, of course)
   - ...

Then when a user registers, simply insert the information they provide into the users table as a new row.

伴我心暖 2024-10-22 12:18:30

那将是巨大的杀伤力。您可能应该阅读数据库设计(从规范化开始,但不要过度)。然后写下你要为每个用户保存的内容,并思考如何保存而不保存数据双重。

但我很确定每个用户一个表不是一个选项。

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.

没有伤那来痛 2024-10-22 12:18:30

您一定对数据库字段(或列)记录(或行)

  • 数据库包含特定项目的所有数据。每个项目总是有一个数据库(或几乎总是)
  • 包含特定实体的所有数据,并且所说的实体是指一种可以想象为真实存在或单独存在的对象类型。人是一个实体,一本书是一个实体,一部电话是一个实体,一部电影是一个实体,等等。其中每一个都是数据库中单独的表。
  • 字段(或列)是一种数据类型,表示表实体的特定特征(特征)。例如,用户表可以包含以下字段:NAMESURNAMEAGE 等。这些都是用户拥有的功能。
  • 一条记录(或行)是一个表的实际项目。它是表实体的单个“部分”。例如,在用户表中,一条记录是一个用户,即 {NAME:"John", SURNAME:"Smith", AGE:"32"}

在您的示例中,我可以肯定地告诉您,您只需要一个数据库。您想要存储许多用户的信息,因此您需要一个名为 USER。您需要存储用户的特征,例如:名字、姓氏、年龄、地址等,然后您需要在此表中创建相应字段NAMESURNAMEAGEADDRESS 等。然后您需要将数据作为记录插入数据库中>。这将是您要存储的每个用户的一条记录。

You must be confusing the meaning of the words database, table, field (or column), record (or row).

  • A database contains all your data for a specific project. There is always one database per project (or almost always)
  • A table contains all data of a specific entity and by saying entity, I mean an object type that is imaginable as real or separately existing by itself. A person is an entity, a book is an entity, a phone is an entity, a movie is an entity, etc. Each of these would be separate tables in a database.
  • A field (or column) is a data type that represents a specific characteristic (feature) of a table's entity. For example a table of users can have the fields: NAME, SURNAME, AGE, etc. These are all features that a user has.
  • A record (or row) is an actual item of one table. It is a single 'piece' of the table's entity. For example in a table of users, one record is one single user, namely {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.

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