I have users who can login on a front-end page, and admins who can login on an admin page.
我的用户可以登录前端页面,管理员可以登录管理页面。
Should both users and admins be "Users" with different roles, or should they be split in different tables?
用户和管理员都应该是具有不同角色的“用户”,还是应该将他们划分到不同的表中?
9 个解决方案
#1
32
Roles should be tracked separately from user accounts, because someone can be promoted (or demoted) over time. Would it make sense in that situation to have two different user accounts, in two different tables? I think not.
角色应该与用户帐户分开跟踪,因为随着时间的推移,某人可能会被提升(或降级)。在这种情况下,在两个不同的表中拥有两个不同的用户帐户是否有意义?我认为不是。
Here's the basic structure I'd use -
这是我要用的基本结构-
USERS
- user_id (primary key)
- user_id(主键)
- user_name
- user_name
ROLES
- role_id (primary key)
- role_id(主键)
- role_name
- role_name
USER_ROLES
- user_id (primary key, foreign key to USERS.user_id)
- user_id(主键,user .user_id的外键)
- role_id (primary key, foreign key to ROLES.role_id)
- role_id(主键,ROLES.role_id的外键)
#2
8
Yes, all users belong in the users table. You also need to have a Roles table and have a FK betweent the two.
是的,所有用户都属于users表。您还需要一个角色表,并在两者之间有一个FK。
#3
8
If admin and users share fields it seems they should go in the same table to avoid duplicating structure. They both have a first name and last name. Both are humans in the real world. This is probably the way it should be.
如果管理员和用户共享字段,那么他们应该使用相同的表来避免重复结构。他们都有名字和姓。两者都是现实世界中的人类。这可能是应该的。
But on the other hand States and Cities both have a name. And both are locations. Should they always go in the same table? Sometimes they do in recursive models. Sometimes they are separate.
但另一方面,州和城市都有自己的名字。和两个位置。他们应该总是坐在一张桌子上吗?有时它们在递归模型中进行。有时他们是分开的。
My thinking...... is admin considered to be a "type" of user in your system? Or is it something truly different where nothing of type "user" applies to it? It depends on what an admin really means in your system. Is the shared structure along the lines of city/state? Or is the shared structure along the lines of "you are TYPE user"?
我的想法……在您的系统中,admin被认为是用户的“类型”吗?或者它真的是一种完全不同的东西,没有任何类型的“用户”适用于它吗?这取决于管理员在系统中的真正含义。共享结构是否沿着城市/州的路线?还是“您是类型用户”这一行的共享结构?
But if in doubt go with putting admins in the user table because I doubt they are truly separate. You will probably want to share an authentication system for both. You will probably want to share account creation for both. Unless admin is some special thing only developers use on the back end.
但是如果有疑问,可以将admins放入用户表中,因为我怀疑它们是真正独立的。您可能希望为两者共享一个身份验证系统。您可能希望为两者共享帐户创建。除非admin是一些只有开发人员在后台使用的特殊东西。
#4
4
The risk one a user accidentally becoming an administrative user shouldn't be bigger than a user accidentally becoming a different user, and that should definitely not happen either.
一个用户意外地成为一个管理用户的风险不应该比一个用户意外地变成一个不同的用户的风险大,这也不应该发生。
Consider that if you have regular users and administrative users in separate tables, you would have a user id in the regular user table matching a user id in the administrative user table. You would have to make sure that one type of user id could never be accidentally used as the other type. It's harder to spot a problem like that, than spotting something that could cause a user id changing into a different user id.
如果在单独的表中有常规用户和管理用户,则在常规用户表中会有一个用户id,在管理用户表中匹配用户id。您必须确保一种类型的用户id永远不会被意外地用作另一种类型。发现这样的问题比发现可能导致用户id更改为不同用户id的内容要困难得多。
#5
2
I'd personally keep "Users" in one table. How you decide to represent roles (e.g. as a static bit on the User table itself, or through advanced RBAC rights) depends on how complex your system is. But a user is a user.
我个人会把“用户”放在一个表中。您决定如何表示角色(例如,作为用户表本身的一个静态位,或者通过高级RBAC权限)取决于您的系统有多复杂。但是用户就是用户。
#6
1
There should be no problem where you keep the users, only problem should be the pages\methods through which you access that information.
在保留用户的地方应该没有问题,唯一的问题应该是访问信息的页面\方法。
It would actually be better to keep both on the same table since they hold the same data type.
实际上,最好将两者保持在同一个表上,因为它们持有相同的数据类型。
#7
1
Make a separate Roles table and a separate User_Roles table. In the first define the roles, in the second join users to their respective roles (it's possible they might have more than one?)
创建一个单独的Roles表和一个单独的User_Roles表。在第一个中定义角色,在第二个连接用户中定义他们各自的角色(他们可能有多个角色?)
#8
1
From a data perspective it makes sense that administrators are users with different roles. There could be a table for each userright, correlating users with their roles. Users can have multiple roles like that, but at the end of the day, an administrator is a user.
从数据的角度来看,管理员是具有不同角色的用户是有意义的。每个用户都可以有一个表,将用户与他们的角色联系起来。用户可以有多个这样的角色,但归根结底,管理员是用户。
#9
0
I belive there is no absolute truth about your question, it depends on your application.
我相信你的问题没有绝对的事实根据你的申请而定。
Two reasons the user-types could be in different tables would be:
用户类型可以在不同的表中有两个原因:
- The types differ in data-structure (detail / address etc..)
- 数据结构(细节/地址等)的类型不同。
- Good sleep. If you manually edit your FK-values (pointing at a user), you avoid the risk of pointing anything to a frontend-user.
- 良好的睡眠。如果您手动编辑您的fk值(指向用户),则可以避免将任何内容指向前端用户的风险。
#1
32
Roles should be tracked separately from user accounts, because someone can be promoted (or demoted) over time. Would it make sense in that situation to have two different user accounts, in two different tables? I think not.
角色应该与用户帐户分开跟踪,因为随着时间的推移,某人可能会被提升(或降级)。在这种情况下,在两个不同的表中拥有两个不同的用户帐户是否有意义?我认为不是。
Here's the basic structure I'd use -
这是我要用的基本结构-
USERS
- user_id (primary key)
- user_id(主键)
- user_name
- user_name
ROLES
- role_id (primary key)
- role_id(主键)
- role_name
- role_name
USER_ROLES
- user_id (primary key, foreign key to USERS.user_id)
- user_id(主键,user .user_id的外键)
- role_id (primary key, foreign key to ROLES.role_id)
- role_id(主键,ROLES.role_id的外键)
#2
8
Yes, all users belong in the users table. You also need to have a Roles table and have a FK betweent the two.
是的,所有用户都属于users表。您还需要一个角色表,并在两者之间有一个FK。
#3
8
If admin and users share fields it seems they should go in the same table to avoid duplicating structure. They both have a first name and last name. Both are humans in the real world. This is probably the way it should be.
如果管理员和用户共享字段,那么他们应该使用相同的表来避免重复结构。他们都有名字和姓。两者都是现实世界中的人类。这可能是应该的。
But on the other hand States and Cities both have a name. And both are locations. Should they always go in the same table? Sometimes they do in recursive models. Sometimes they are separate.
但另一方面,州和城市都有自己的名字。和两个位置。他们应该总是坐在一张桌子上吗?有时它们在递归模型中进行。有时他们是分开的。
My thinking...... is admin considered to be a "type" of user in your system? Or is it something truly different where nothing of type "user" applies to it? It depends on what an admin really means in your system. Is the shared structure along the lines of city/state? Or is the shared structure along the lines of "you are TYPE user"?
我的想法……在您的系统中,admin被认为是用户的“类型”吗?或者它真的是一种完全不同的东西,没有任何类型的“用户”适用于它吗?这取决于管理员在系统中的真正含义。共享结构是否沿着城市/州的路线?还是“您是类型用户”这一行的共享结构?
But if in doubt go with putting admins in the user table because I doubt they are truly separate. You will probably want to share an authentication system for both. You will probably want to share account creation for both. Unless admin is some special thing only developers use on the back end.
但是如果有疑问,可以将admins放入用户表中,因为我怀疑它们是真正独立的。您可能希望为两者共享一个身份验证系统。您可能希望为两者共享帐户创建。除非admin是一些只有开发人员在后台使用的特殊东西。
#4
4
The risk one a user accidentally becoming an administrative user shouldn't be bigger than a user accidentally becoming a different user, and that should definitely not happen either.
一个用户意外地成为一个管理用户的风险不应该比一个用户意外地变成一个不同的用户的风险大,这也不应该发生。
Consider that if you have regular users and administrative users in separate tables, you would have a user id in the regular user table matching a user id in the administrative user table. You would have to make sure that one type of user id could never be accidentally used as the other type. It's harder to spot a problem like that, than spotting something that could cause a user id changing into a different user id.
如果在单独的表中有常规用户和管理用户,则在常规用户表中会有一个用户id,在管理用户表中匹配用户id。您必须确保一种类型的用户id永远不会被意外地用作另一种类型。发现这样的问题比发现可能导致用户id更改为不同用户id的内容要困难得多。
#5
2
I'd personally keep "Users" in one table. How you decide to represent roles (e.g. as a static bit on the User table itself, or through advanced RBAC rights) depends on how complex your system is. But a user is a user.
我个人会把“用户”放在一个表中。您决定如何表示角色(例如,作为用户表本身的一个静态位,或者通过高级RBAC权限)取决于您的系统有多复杂。但是用户就是用户。
#6
1
There should be no problem where you keep the users, only problem should be the pages\methods through which you access that information.
在保留用户的地方应该没有问题,唯一的问题应该是访问信息的页面\方法。
It would actually be better to keep both on the same table since they hold the same data type.
实际上,最好将两者保持在同一个表上,因为它们持有相同的数据类型。
#7
1
Make a separate Roles table and a separate User_Roles table. In the first define the roles, in the second join users to their respective roles (it's possible they might have more than one?)
创建一个单独的Roles表和一个单独的User_Roles表。在第一个中定义角色,在第二个连接用户中定义他们各自的角色(他们可能有多个角色?)
#8
1
From a data perspective it makes sense that administrators are users with different roles. There could be a table for each userright, correlating users with their roles. Users can have multiple roles like that, but at the end of the day, an administrator is a user.
从数据的角度来看,管理员是具有不同角色的用户是有意义的。每个用户都可以有一个表,将用户与他们的角色联系起来。用户可以有多个这样的角色,但归根结底,管理员是用户。
#9
0
I belive there is no absolute truth about your question, it depends on your application.
我相信你的问题没有绝对的事实根据你的申请而定。
Two reasons the user-types could be in different tables would be:
用户类型可以在不同的表中有两个原因:
- The types differ in data-structure (detail / address etc..)
- 数据结构(细节/地址等)的类型不同。
- Good sleep. If you manually edit your FK-values (pointing at a user), you avoid the risk of pointing anything to a frontend-user.
- 良好的睡眠。如果您手动编辑您的fk值(指向用户),则可以避免将任何内容指向前端用户的风险。