I’m working on an application where users have different permissions to use different features (e.g. Read, Create, Download, Print, Approve, etc.). The list of permissions isn’t expected to change often. I have a couple of options of how to store these permissions in the database.
In what cases would Option 2 be better?
Option 1
Use an associative table.
User ---- UserId (PK) Name Department
Permission ---- PermissionId (PK) Name
User_Permission ---- UserId (FK) PermissionId (FK)
Option 2
Store a bitmask for each user.
User ---- UserId (PK) Name Department Permissions
[Flags]
enum Permissions {
Read = 1,
Create = 2,
Download = 4,
Print = 8,
Approve = 16
}