Refresh enumeration: The application bit flag is applied to the database table for query.

Source: Internet
Author: User

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.
------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.