是否应该在 Web 应用程序上为每个用户创建一个新表?

发布于 2024-10-07 08:00:36 字数 286 浏览 0 评论 0原文

我正在编写我的第一个 Web 应用程序,并且我对数据库有足够的了解,知道架构很重要,但不足以知道如何实际编写一个好的应用程序。

是否有一个标准协议来处理每个用户帐户中存储的信息?我的直觉是拥有一张存储用户密钥和登录信息的表,以及其表的句柄(可能是密钥?),然后为每个用户拥有一张表。

但我想知道为每个用户设置表是否存在性能问题,或者这似乎是一种非常愚蠢的方法。这似乎应该是一个“已解决的问题”,因为基本上所有网络应用程序都有用户帐户,但我无法通过搜索找到任何内容。是否有任何具有“已解决”模式的资源用于存储各种类型的网络数据?

I'm writing my first web app, and I know enough about databases to know that the schema is important but not enough to know how to actually write a good one.

Is there a standard protocol for handling information stored in each user account? My instinct is to have one table that stores the user's key and log-in info, and a handle to their table (probably the key?), and then have one table for each user.

But I wonder if there are performance issues around having table for each user or if that seems an incredibly stupid way to do it. This seems like it should be a "solved problem" since basically all web apps have user accounts, but I haven't been able to find anything via search. Are there any resources with "solved" schemas for storing various sorts of web data?

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

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

发布评论

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

评论(3

囍孤女 2024-10-14 08:00:36

通常,您不会为每个用户创建单独的表 - 该解决方案无法很好地扩展。

相反,您通常将所有用户的数据放入一个表中(或每种数据类型一个表),并在 WHERE 子句中使用条件来确保用户只能读/写自己的数据。

Usually you would not create a separate table for each user - this solution does not scale well.

Instead you usually put all users' data into a single table (or one table per type of data) and use conditions in the WHERE clause to ensure that a user can only read/write their own data.

扶醉桌前 2024-10-14 08:00:36

除非您的应用程序是非常自定义的,否则您将需要选择一个要使用的网络应用程序框架。对于简单的事情,最常见的框架几乎同样有效(尽管对此存在一些激烈的分歧)。我假设你有一种你认为自己最强大的编程语言,所以我建议你让它成为你的 Web 框架的主要指南。按语言划分的一些常见框架如下(这甚至不是一个详尽的列表):

至于您关于架构的问题,您可能需要研究 数据库规范化。大多数框架已经拥有处理用户创建和身份验证的工具,但通常您永远不会希望为每个用户创建一个表。更常见的方法是创建一个名为 users 的表,该表将某个 id 作为主键,然后将其用作引用其他数据的外键。

Unless your app is something extremely custom, you will want to choose a web-app framework to work with. For the simple things most common frameworks work just about equally well (though there is some rabid disagreement on that). I will assume that you have a programming language where you feel you are the most strong so I would suggest you let that be your primary guide for a web framework. Some common frameworks by language are (this is not even a close to an exhaustive list):

As to your question about the schema, you might want to look into database normalization. Most frameworks will already have tools to deal with user creation and authentication, but in general you will never want to create a table per user. More common approach is to have a table called users, that had some id as a primary key and that is then used as a foreign key that references other data.

就像说晚安 2024-10-14 08:00:36

是的,绝对不是一个好主意。您应该做的是熟悉一些 Web 应用程序框架,因为大多数/全部都已经为您提供了这些框架。例如 Django 就是不错的选择。

Yeah definitely not a good idea. What you should do, is to get familiar with some web application framework because most/all of them provide this for you already. Good choice is for example Django.

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