Page 3 - Simple Queries in SQL
P. 3

•   BINARY
                   •   VARBINARY
                   •   BLOB
                   •   TEXT
                   •   ENUM
                   •   SET

               CHAR and VARCHAR Types
               The CHAR and VARCHAR types are similar but differ in the way they are stored and retrieved. They
               also differ in maximum length and in whether trailing spaces are retained.

                    Types                Description               Display         Range in characters
                                                                   Format
                 CHAR         Contains non-binary strings. Length  Trailing spaces  The length can be any value
                              is fixed as you declare while     are removed.    from 0 to 255.
                              creating a table. When stored, they
                              are right-padded with spaces to the
                              specified length.
                 VARCHAR      Contains non-binary strings.      As stored.      A value from 0 to 255 before
                              Columns are variable-length                       MySQL 5.0.3, and 0 to
                              strings.                                          65,535 in 5.0.3 and later
                                                                                versions.

               BINARY and VARBINARY Types
               The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain
               binary strings rather than nonbinary strings.

                 Types        Description            Range in bytes

                 BINARY       Contains binary strings.   0 to 255

                 VARBINARY  Contains binary strings.   A value from 0 to 255 before MySQL 5.0.3, and 0 to
                                                     65,535 in 5.0.3 and later versions.


               BLOB and TEXT Types
               A BLOB is a binary large object (such as images or other types of files) that can hold a variable
               amount of data. There are four types of BLOB, TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB.
               These differ only in the maximum length of the values they can hold.

               The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the
               four BLOB types and have the same maximum lengths and storage requirements.

                 Types     Description             Categories        Range
                 BLOB      Large binary object that  TINYBLOB        Maximum length of 255 characters.
                           containing a variable   BLOB              Maximum length of 65535
                           amount of data. Values                    characters.
                           are treated as binary   MEDIUMBLOB        Maximum length of 16777215
                           strings. You don't need                   characters.
                           to specify length while   LONGBLOB        Maximum length of 4294967295
                           creating a column.                        characters
   1   2   3   4   5   6   7   8