MEDIUMBLOB
and
MEDIUMTEXT
Identical to
BLOB
and TEXT, respectively, except that a maximum of 16,777,215 bytes can be stored.
LONGBLOB
and
LONGTEXT
Identical to
BLOB
and TEXT, respectively, except that a maximum of four gigabytes of data can be stored. The effective maximum can vary depending on the memory available on the server and its configuration.
ENUM('
value1'[,'
value2'[, A list, or
enumeration of string values.
A column of type ENUM
can beset to a value from the list
value1,
value2, and soon, up to a maximum of 65,535 different values.
While the values are stored
and retrieved as strings, what’s stored in the database is an integer representation. The enumerated column can contain
NULL
(stored as
NULL
), the empty string 'stored as
0
), or any of the valid elements (stored as
1
,
2
,
3
, and soon.
You can prevent NULL
values from being accepted by declaring the column as NOT NULL
when creating the table.
This type is a compact way of storing values from
a list of predefined values, such as state or country names. Consider this example using fruit names the name can be anyone of the predefined values Apple, Orange, or
Pear
(in
addition to NULL
and the empty string):
mysql>
CREATE TABLE fruits_enum ( fruit_name ENUM('Apple', 'Orange, 'Pear) );Query OK, 0 rows affected (0.00 sec)
mysql>
INSERT INTO fruits_enum VALUES ('Apple');Query OK, 1 row affected (0.00 sec)
If you try inserting a value that’s not in the list, MySQL warns you that it didn’t store the data you asked:
mysql>
INSERT INTO fruits_enum VALUES ('Banana');Query OK, 1
row affected, 1 warning (0.00 sec)
mysql>
SHOW WARNINGS;+---------+------+-------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------+
| Warning | 1265 | Data truncated for column 'fruit_name' at row 1 |
+---------+------+-------------------------------------------------+
1 row inset sec)
Similarly, a list of several allowed values isn’t accepted either:
mysql>
INSERT INTO fruits_enum VALUES ('Apple,Orange');Query OK, 1 row affected, 1 warning (0.00 sec)
mysql>
SHOW WARNINGS;+---------+------+-------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------+
| Warning | 1265 | Data truncated for column 'fruit_name' at row 1 |
Share with your friends: