简体   繁体   English

存储多个用户属性集合的最佳方法

[英]Best way to store multiple user attribute collection

Question about best db design practices for the following scenario: 有关以下情况的最佳数据库设计实践的问题:

I have a user table which stores information like password, the department user belongs to, Email etc I also have to create another table to store user access information. 我有一个用户表,用于存储诸如密码,部门用户所属的部门,电子邮件等信息,我还必须创建另一个表来存储用户访问信息。 I have users with access as following: 我具有以下访问权限的用户:

  1. userid 123 : [line of business: abc, xyz,etc], [Role: Team leader, Regular User etc], [Company: 1234, 54666, etc] 用户ID 123:[业务范围:abc,xyz等],[角色:团队负责人,常规用户等],[公司:1234、54666等]
  2. userid 345: [line of business: abc, xyz, 987, etc], [Role: Team leader, Maintenance etc], [Company: 1234, 54666, etc] userid 345:[业务范围:abc,xyz,987等],[角色:团队负责人,维护等],[公司:1234、54666等]

Basically, a user can have any combinations of different access for each of these categories. 基本上,对于这些类别中的每一个,用户可以具有不同访问权限的任何组合。

The way i was thinking is in this table, create 3 columns for each type of access and store each category in the form of xml, otherwise i have to create 3 different tables for each categories, t_user_Lob, t_user_role, t_user_company. 我在该表中的思维方式是,为每种访问类型创建3列,并以xml的形式存储每个类别,否则我必须为每种类别(t_user_Lob,t_user_role,t_user_company)创建3个不同的表。

what is the best way to do this? 做这个的最好方式是什么?

I also thought about storing them as csv values in each column but i heard that it's goes against the relational normalization rules. 我还考虑过将它们作为csv值存储在每一列中,但我听说这违反了关系规范化规则。

I also like json way to storing data but i am using sql server 2012 and it's hell to parse/compare values in json columns in 2012. 我也喜欢json的方式来存储数据,但是我正在使用sql server 2012,2012年解析/比较json列中的值真是太难了。

Thanks 谢谢

I would store them in three separate tables. 我将它们存储在三个单独的表中。

Your question isn't clear about what relationships are needed, but basically you use three tables to create a many-to-many relationship. 您的问题尚不清楚需要什么关系,但是基本上您使用三个表来创建多对多关系。

Entity A
Entity B
Relationship (A - B)

Assuming the combinatorics aren't outlandish, I would create a table, call it user_access, with every combination of role and company and give each row a unique value. 假设组合函数并不奇怪,我将创建一个表,将其称为user_access,其中包含角色和公司的每种组合,并为每一行赋予唯一的值。 Then create a third table, call it user_access_people with a user ID and an associated user_access value. 然后创建第三个表,将其称为具有用户ID和关联的user_access值的user_access_people。 So user_access_people would have your many to many relationship between user_id and user_access_Id. 因此,user_access_people将在user_id和user_access_Id之间建立多对多关系。 It would have multiple rows per each user_ID when necessary. 必要时,每个user_ID会有多行。

You can then join these tables to check for whatever value from the user_access columns that you are looking for. 然后,您可以将这些表联接起来,以从所需的user_access列中检查任何值。

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

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