For database tables with permission management, if there is a table user and permission, it indicates that a user has n roles. There are two solutions:
1) Add a userpermissions table to save the primary keys of user and permission, such as the database installed in Asp.net.
2) Add a field, such as permissions, to the user table and save the content, for example, 1, 2, 3, and 4.
The advantage of the second processing method is to reduce a table, but the query should be a bit troublesome: Split characters? Use like?
For the second method, if enumeration is applied, a Permissions enumeration is created and the bit flag is applied:
[Flags]
Public Enum Permissions
{
View = 1,
Add = 2,
Edit = 4,
Delete = 8,
All = View | add | edit | Delete
}
The data in the permission table is consistent with the enumerated values in permissions.
Modify permissions to the int type. When saving the permissions to the database, take the int value of permissions, for example, permissions. Add | permissions. Edit. The value is 6.
If you search for a user with the permissions. Add permission, you can use statements similar to select * from user where permissions & 2 = 2.
Sql2005express cannot be started, so there is no more code post.
------------------------------------------------------------------------------