Returning to the directory sometimes, when designing the table structure, some fields may have several statuses at the same time. For example, the file attributes of Xiaowei are also in this situation. They are read-only, archived, and hidden, but when you set attributes for a file, you can actually grant these three attributes to an object at the same time. This is normal for us. How can we implement these attributes in the program?
Returning to the directory sometimes, when designing the table structure, some fields may have several statuses at the same time. For example, the file attributes of Xiaowei are also in this situation. They are read-only, archived, and hidden, but when you set attributes for a file, you can actually grant these three attributes to an object at the same time. This is normal for us. How can we implement these attributes in the program?
Back to directory
Sometimes, when designing a table structure, some fields may have several statuses at the same time. For example, the file attributes of Xiaowei are also in this situation. "Read-only, archive, hide ", but when you set attributes for a file, you can actually grant these three attributes to an object at the same time. This is normal for us. How can we implement these attributes in the program?
First, an enumeration. The SQL statement may be a table or a specified number of values, such as read-only 1, archive 2, and hide 3.
I don't think the. net source code is stored in this way.
File Attribute: Read-Only + archive; Value: 1, 2
We can see that it is used, separated, and then separately summed.
But after I read the. net source code, my practice has changed, that is, using the displacement operation, we should say that there is a leap from performance to program definition.
The file attribute is read-only and archive. The value is 3 (3 = 1 + 2)
Of course, how can we achieve this when we need to query records containing the attributes of archive (2) in the database?
In fact, the offset operator numbers in SQL and C # are exactly the same. It has the following situations:
1 update User_Info set Status = Status | 8 where UserID = 1 -- update the status field in user_info and add 82 3 update User_Info set Status = Status &(~ 8) where UserID = 1 -- update the status field in user_info and subtract 8 from the original value. If the original value does not contain 8, add 8 4 5 select * from User where Status & 8> 0 to the original value -- find the records with 8 contained
Well, it's quite convenient. It's just superficial. In fact, its query performance is far higher than that of the first character concatenation method.
Back to directory