Data stored in a database comes in all shapes and sizes.
Some fields store only numbers, some only text, and others a combination of the
two. Some databases also support specialized types: dates and times, binary
strings and Booleans.
Selecting from available data types to find the best match
for your data is an important part of database design, because such type
selection affects the efficiency and performance of your RDBMS. Therefore, it’s
extremely important to be fully aware of the options available to you in your
RDBMS, and to select the most appropriate data type for your storage needs at
the time of design itself.
That’s where this document comes in. It outlines (Table A) the most important data types
supported by MySQL, one of the most popular free RDBMS currently
available, and describes when and how each should be used. It thus serves as a
ready resource to help you in creating an optimal design for your databases.
Table A
Data Type |
Description |
Bytes Used |
Recommended Use |
SMALLINT |
Integer |
2 |
Storing Examples: |
INT |
Integer |
4 |
Storing Example: |
BIGINT |
Extremely |
8 |
Storing Example: |
FLOAT |
Single-precision |
4 |
Storing Examples: |
DOUBLE |
Double-precision |
8 |
Storing Examples: Scientific values |
DECIMAL |
Floating-point |
Variable; |
Storing Examples: Currency amounts, scientific values |
CHAR |
Fixed-length |
Specified |
Storing Examples: |
VARCHAR |
Variable-length |
Variable; |
Storing Examples: |
TEXT |
Variable-length |
Variable; |
Storing Examples:
|
BLOB |
Binary |
Variable; |
Storing Examples: Images, attachments, binary documents
|
DATE |
Date |
3 |
Storing Examples: |
TIME |
Time |
3 |
Storing Example: |
DATETIME |
Combined |
8 |
Storing Examples: Reminders, events |
TIMESTAMP |
Combined |
4 |
Recording Examples: Event triggers, “last log-in” |
YEAR |
Year |
1 |
Storing Examples: Graduation years, birth years |
ENUM |
A |
1 |
Storing Examples: Boolean selections like Gender |
SET |
A |
Between |
Storing Examples: Multiple-choice selections like Hobbies and |
For a complete list and detailed descriptions, see the MySQL manual. You should
also read the article entitled Choosing
the Right Type for a Column.