0

If I understand correctly, the pre MySQL 5.0.3 interpretation of the BIT data type meant it could be used as a series of flags? If this is the case I can see practical uses for it in MySQL but imagine it would not have been as efficient as using SET.

Even if the above is not the case, I have great difficulty in understanding how the current implementation of the BIT data type can be practically applied in a database. If anyone is able to provide a simplified explanation and, an example of where it would be applicable, I would be grateful.

I have searched for descriptions and examples elsewhere but have been unsuccessful in finding examples applicable solely to databases.

4

1 回答 1

0

假设您有带有属性字段的行

属性定义为

1  - Has property 1
2  - Has property 2
4  - Has property 3
8  - Has property 4

分配属性 1 和 2(即只清理其他 1 和 2 个)

 set status = status & 3

添加属性 3

 set status = status | 4

删除属性 1

 set status = status | 14

选择具有属性 1 和 2 的行

SELECT .. WHERE (属性 & 3) = 3

选择属性 1 或 2 所在的行

SELECT .. WHERE (Properties & 1) = 1 OR (Properties & 2) = 2

于 2010-08-25T15:21:56.850 回答