Database Reference
In-Depth Information
Appendix C
MariaDB Datatypes
As explained in Chapter 1, “Understanding SQL,” datatypes are basically rules
that define what data may be stored in a column and how that data is actually
stored.
Datatypes are used for several reasons:
Datatypes enable you to restrict the type of data that can be stored
in a column. For example, a numeric datatype column only accepts
numeric values.
Datatypes allow for more efficient storage, internally. Numbers and
date time values can be stored in a more condensed format than text
strings.
Datatypes allow for alternate sorting orders. If everything is treated as
strings, 1 comes before 10 , which comes before 2 . (Strings are sorted
in dictionary sequence, one character at a time starting from the left.)
As numeric datatypes, the numbers would be sorted correctly.
When designing tables, pay careful attention to the datatypes being used.
Using the wrong datatype can seriously impact your application. Changing the
datatypes of existing populated columns is not a trivial task. (In addition, doing
so can result in data loss.)
Although this appendix is by no means a complete tutorial on datatypes and
how they are to be used, it explains the major MariaDB datatype types, and
what they are used for.
String Datatypes
The most commonly used datatypes are string datatypes. These store strings:
for example, names,
addresses, phone numbers, and Zip Codes. As listed in
Table D.1, there are basically two types of string datatype that you can use—
fixed-length strings and variable-length strings.
 
 
 
Search WWH ::




Custom Search