How can I get enum possible values in a MySQL database?

MySQLMySQLi Database

We can achieve possible enum value with the help of ‘enum’. The following is the syntax.

yourColumnName ENUM(value1,value2,........................N)

Let us first create a table.

mysql> create table EnumDemo
   -> (
   -> Light int,
   -> IsONOrOff ENUM('ON','OFF')
   -> );
Query OK, 0 rows affected (1.06 sec)

In the above table, ENUM is used to get the possible value for “Light”.

Inserting records.

mysql> insert into EnumDemo values(1,'ON'),(0,'OFF');
Query OK, 2 rows affected (0.24 sec)
Records: 2  Duplicates: 0  Warnings: 0

To display all the records −

mysql> select *from EnumDemo;

Here is the output. The ENUM values are visible.

+-------+-----------+
| Light | IsONOrOff |
+-------+-----------+
|     1 | ON        |
|     0 | OFF       |
+-------+-----------+
2 rows in set (0.07 sec)
raja
Published on 22-Nov-2018 12:29:42
Advertisements