SET
1-8 members: 1 byte |
9-16 members: 2 bytes |
17-24 members: 3 bytes |
25-32 members: 4 bytes |
33-64 members: 8 bytes |
A list of values taken from a predefined set of values. A field can
contain any number—including none—of the strings
specified in the SET
statement. A
SET
is basically an ENUM
that
allows each field to contain more than one of the specified values. A
SET
, however, is not stored according to index but
as a complex bit map. Given a SET
with the members
Orange
, Apple
,
Pear
, and Banana
, each element
is represented by an “on” bit in a
byte, as shown in Table 16-2.
Member |
Decimal value |
Bitwise representation |
|
1 |
0001 |
|
2 |
0010 |
|
4 |
0100 |
|
8 |
1000 |
The values Orange
and Pear
are
therefore stored in the database as 5 (0101).
You can store a maximum of 64 values in a SET
column. Though you can assign the same value multiple times in an SQL
statement updating a SET
column, only a single
value will actually be
stored.