SQL表设计帮助
我接管了一个具有 SQL 后端的应用程序。有多个表,但我关心的两个是:
QAProfile
---------
ProfileID <pk> -int
ProfileName
SecurityGroups -varchar(max)
SecurityGroups
--------------
GroupID <pk> -int
GroupName
我的问题是 SecurityGroups 字段是一个以逗号分隔的 GroupID 值列表。
因此,配置文件表如下所示:
--------------------------------------------
| ProfileID | ProfileName | SecurityGroups |
--------------------------------------------
| 1 | foo | ,1,13,34,56, |
--------------------------------------------
| 2 | bar | ,4,13,29,56, |
--------------------------------------------
一个配置文件可以有多个安全组,一个安全组可以位于多个配置文件上
对于如何重新设计这个有什么建议吗?
I've taken over an application that has a SQL backend. There are multiple tables, but the two that I'm concerned about are these:
QAProfile
---------
ProfileID <pk> -int
ProfileName
SecurityGroups -varchar(max)
SecurityGroups
--------------
GroupID <pk> -int
GroupName
My issue is that the the SecurityGroups field is a comma delimited list of GroupID values.
So the Profile table looks like this:
--------------------------------------------
| ProfileID | ProfileName | SecurityGroups |
--------------------------------------------
| 1 | foo | ,1,13,34,56, |
--------------------------------------------
| 2 | bar | ,4,13,29,56, |
--------------------------------------------
A profile can have muliple security groups and a security group can be on muliple profiles
Any suggestions on how to re-engineer this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您希望重新设计它是件好事,因为一般来说逗号分隔的列表不属于 SQL 数据库。
看起来一个简单的联结表可以替换
SecurityGroups
列QAProfile
表:It's good that you're looking to re-engineer this, since in general comma-delimited lists don't belong to SQL databases.
It looks like a simple junction table can replace the
SecurityGroups
column of theQAProfile
table:如果是我,我会这样做:
If it was me, I would do it like this:
ProfileSecurityGroups
ProfileSecurityGroups
是的,小菜一碟,您可以创建一个像这样的联结表:
Yes piece of cake you could just create a junction table like this:
应添加一个新的表 ProfileToGroup:
个人资料ID
GroupID
A new Table ProfileToGroup should be added:
ProfileID
GroupID