This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-22. For the latest, interactive version please visit https://mariadb.com/kb/.

ENUM

Sintassi

ENUM('valore1','valore2',...) [CHARACTER SET set_di_caratteri] [COLLATE nome_collation]

Spiegazione

Una enumerazione. Un oggetto stringa che può avere un solo valore, scelto dalla lista di valori 'valore1', 'valore2', ..., NULL o il valore di errore ''. Una colonna ENUM può avere un massimo di 65,535 valori distinti. I valori ENUM internamente sono rappresentati come interi.

Esempi

MariaDB [test]> create table frutta (
    -> id INT NOT NULL auto_increment PRIMARY KEY,
    -> fruit ENUM('mela','arancia','pera'),
    -> bushels INT);
Query OK, 0 rows affected (0.30 sec)

MariaDB [test]> describe frutta;
+---------+-------------------------------+------+-----+---------+----------------+
| Field   | Type                          | Null | Key | Default | Extra          |
+---------+-------------------------------+------+-----+---------+----------------+
| id      | int(11)                       | NO   | PRI | NULL    | auto_increment |
| frutto  | enum('mela','arancia','pera') | YES  |     | NULL    |                |
| cesti   | int(11)                       | YES  |     | NULL    |                |
+---------+-------------------------------+------+-----+---------+----------------+
3 rows in set (0.03 sec)

MariaDB [test]> INSERT INTO frutta
    -> (frutto,cesti) VALUES
    -> ('pera',20),
    -> ('mela',100),
    -> ('arancia',25);
Query OK, 3 rows affected (0.14 sec)
Records: 3  Duplicates: 0  Warnings: 0

MariaDB [test]> INSERT INTO frutta
    -> (frutto,cesti) VALUES
    -> ('avocado',10);
ERROR 1265 (01000): Data truncated for column 'fruit' at row 1

MariaDB [test]> select * from fruits;
+----+---------+---------+
| id | frutto  | cesti   |
+----+---------+---------+
|  1 | pera    |      20 |
|  2 | mela    |     100 |
|  3 | arancia |      25 |
+----+---------+---------+
3 rows in set (0.01 sec)

MariaDB [test]> 

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.