I have the following tables (among others):
- Users
- Departments
- Roles
- UserRoles
The UserRoles
table has the following fields:
- UserId
- RoleId
- DepartmentId (NULL)
The idea here is I can give a user a specific role, for specific department(s), if the DepartmentId
is NULL, then this role applies to all departments.
The problem here I cannot make a composite primary key out of the three fields in the UserRoles
table since the DepartmentId
is nullable.
Should I just go with a unique index without a primary key since I cannot have a primary key for the first two columns only (that will prevent the user from having the same role to multiple departments), or should I change the whole structure to something else (any ideas will be appreciated).