【发布时间】:2023-03-17 10:21:01
【问题描述】:
将数组保存在表格列中是否明智?更准确地说,我正在考虑以下模式,据我所知,它违反了规范化:
create table Permissions(
GroupID int not null default(-1),
CategoryID int not null default(-1),
Permissions varchar(max) not null default(''),
constraint PK_GroupCategory primary key clustered(GroupID,CategoryID)
);
还有这个:
create table Permissions(
GroupID int not null default(-1),
CategoryID int not null default(-1),
PermissionID int not null default(-1),
constraint PK_GroupCategory primary key clustered(GroupID,CategoryID)
);
UPD3:我将权限设想为逗号分隔的字符串,因为 MSSQL 是我们的主要部署目标。
UPD:忘了提,在这个具体问题的范围内,我们将考虑不会执行“获取具有权限 X 的行”,而是所有查找将仅由 GroupID 和 CategoryID 进行
UPD2:我设想的典型使用场景如下:
int category_id=42;
int[] array_of_groups=new int[]{40,2,42};
if(!Permissions.Check(category_id, array_of_groups, Permission.EatAndDrink)) {
throw new StarveToDeathException();
}
想法?
提前致谢!
【问题讨论】:
标签: sql arrays normalization