mysql data type

INT             4 bytes
FLOAT           4 bytes
DATE            3 bytes  <-- "0000-00-00"
TIME            3 bytes  <-- "00:00:00"
TIMESTAMP        4 bytes

CHAR(N)         N bytes
VARCHAR
BLOB、TEXT
ENUM
SET

ENUM / SET

define columns that can contain only a given set of values.

Difference

ENUM - only one of the choices.
SET  - zero to all of the choices.

* ENUM columns always have a default value

 insert an incorrect value

SET: the incorrect value is ignored.
ENUM: column with IGNORE, it is set to the reserved enumeration value of 0

Set

create:

SET('one', 'two') NOT NULL

any of these values:

''
'one'
'two'
'one,two'

* maximum of 64 distinct members

Usage:

mysql> SELECT * FROM tbl_name WHERE FIND_IN_SET('value',set_col)>0;
mysql> SELECT * FROM tbl_name WHERE set_col LIKE '%value%';

ENUM

create:

name ENUM('small', 'medium', 'large')

*  maximum of 65,535 distinct elements

Creative Commons license icon Creative Commons license icon