David Dury
David Dury

Reputation: 5717

SQL Server database design users, groups, roles, memebers

I have the following SQL Server db with one table so far.

----------------
|Users         | 
----------------
| UserId    PK |
|              |
| Other fields |
----------------

I need to add few more tables to it which is not a problem but this is the goal:

----------------    ----------------    ----------------   ---------------- 
|Users         |    |Roles         |    | Teams       |    | Groups       | 
----------------    ----------------    ----------------   ---------------- 
| UserId    PK |    | RoleId    PK |    | TeamId    PK |   | GroupId   PK | 
|              |    |              |    |              |   |              | 
| Other fields |    | Other fields |    | Other fields |   | Other fields | 
----------------    ----------------    ----------------   ---------------- 

What I need to achieve is the following:

I have some hard time understanding the relation between those tables.

Here is what I managed to achieve based on the answer from @Robertas Valeika.

enter image description here

Upvotes: 2

Views: 6750

Answers (1)

Robertas Valeika
Robertas Valeika

Reputation: 126

You need 3 more tables. UsersRoles UsersRolesGroups UsersRolesTeams.

Relationships:

UsersRoles - UsersRolesGroups, Groups - UsersRolesGroups

UsersRoles - UsersRolesTeams, Teams - UsersRolesTeams

Users - UsersRoles, Roles - UsersRoles.

And add FK to users in groups and teams tables to identify creator of group and team.

Upvotes: 4

Related Questions