String Datatypes
These datatypes are case-sensitive.
So, lowercase and uppercase letters remain unchanged when stored or
retrieved. For a few of the string datatypes, a maximum column width
may be specified. If a string is entered in a column that exceeds the
width set for the column, the string will be right-truncated when
stored. The CHAR
datatype is a fixed-width column.
Columns are right-padded with spaces when stored. The
VARCHAR
datatype adjusts its width and does not
pad the strings stored. Any trailing spaces contained in a string
that is stored are removed.
As of Version 4.1 of MySQL, the
ASCII
attribute may be specified for use with the
CHAR
datatype. This will set the column to the
latin1
character set. As of Version 4.1 of MySQL,
the UNICODE
attribute may be specified for use
with the CHAR
datatype. This will set the column
to the ucs2
character set.
The BINARY
and
VARBINARY
datatypes store data as binary strings
and not character strings like CHAR
. Table A-4 lists the various types and their maximum
sizes. Some types are listed together: BLOB
(Binary Large Object) and TEXT
. They have the same
maximum value, but TEXT
-type columns are handled
based upon their character set, whereas BLOB
types
are not; they’re handled as binary strings. This
becomes a factor in sorting and comparing data. Binary strings are
case-sensitive. As of Version 4.1 of MySQl, you can assign a
character set to a TEXT
type of column. Values are sorted based on the collation of the character set for ...
Get MySQL in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.