Databases Reference
In-Depth Information
Bit column type
MySQL 5.0.3 introduced true bit columns. These take the same amount of space
in the database as the number of bits in their definition. Let us say we have the
following three pieces of information about each topic, and each piece can only be
true (1) or false (0):
• Book is hard cover
• Topic contains a CD-ROM
• Topic is available only in electronic format
We will use a single
BIT
column to store these three pieces of information. Therefore,
we add a column having a length of
3
(which means 3 bits) to the
topic
table:
To construct and subsequently interpret the values we store in this column, we have
to think in binary, respecting the position of each bit within the column. To indicate
that a topic is hard cover, does not contain a CD-ROM, and is available only in
electronic format, we would use a value of
101
.
Search WWH ::
Custom Search