[译]MySQL的Set数据类型
原文地址:http://dev.mysql.com/tech-resources/articles/mysql-set-datatype.html
最近经常被使用的一个MySQL数据类型不得不算SET数据类型了,SET数据类型是一个String类型,但是由于其涉及复杂的增加,所以常常作为一个组合类型被提及到。在创建表的时候,一个SET类型可以存储指定的字符串的预定义列表中的任何数量的字符串。从SET数据类型与ENUM数据类型的预定义字符集工作方式来说,他们是相似的,但是ENUM数据类型限制你的预定义字符串集合中的一个成员,SET数据类型容许你存储多个预定义字符串,没有任何一个字符串,或者所有的字符串,都可以。
在MySQL的表里面,SET数据类型是作为一个Integer值被存储的。根据可利用元素的数量,SET数据类型将占用了0到8个字节。
MySQL的SET数据类型的要求
| 元素的个数 | 字节数 |
| 1 – 8 | 1 |
| 9 – 16 | 2 |
| 17 – 24 | 3 |
| 25 – 32 | 4 |
| 33 – 64 | 8 |
The SET elements are stored in the MySQL table as a bitmap: each element is represented by a single bit. To demonstrate this, lets look at the following sample table, which will be the basis for the rest of this tutorial. (NOTE: In the examples that follow, there are never whitespaces between elements and their comma seperators. Also note that only during the definition of a set are the elements individually wrapped in single quotes, otherwise the set as a whole gets only one set of quotes. Please do likewise.)
在MySQL的表里面,SET元素当作一个bitmap来存储的:每个元素都通过一个单一比特来代表。为了说明这个,让我们来看看下面的表。
| Print article | This entry was posted by Herbert on 2009/08/25 at 18:30, and is filed under Database. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |