Set options while creating a MySQL table. Display the same options as well

MySQLMySQLi Database

To display, use DESC command or information_schema.columns. Let us first create a table and set options −

mysql> create table DemoTable
(
   Color SET('RED','GREEN','BLUE','YELLOW')
);
Query OK, 0 rows affected (0.47 sec)

Case 1

Here is the query to get the list of available options for SET using the DESC command −

mysql> desc DemoTable;

This will produce the following output −

+-------+------------------------------------+------+-----+---------+-------+
| Field | Type                               | Null | Key | Default | Extra |
+-------+------------------------------------+------+-----+---------+-------+
| Color | set('RED','GREEN','BLUE','YELLOW') | YES  |     | NULL    |       |
+-------+------------------------------------+------+-----+---------+-------+
1 row in set (0.00 sec)

Case 2

Here is the query for a list of available options for SET using the information_schema.columns concept −

mysql> select column_type from information_schema.columns
where table_name = 'DemoTable'
and column_name = 'Color';

This will produce the following output −

+------------------------------------+
| COLUMN_TYPE                        |
+------------------------------------+
| set('RED','GREEN','BLUE','YELLOW') |
+------------------------------------+
1 row in set (0.01 sec)
raja
Published on 24-Sep-2019 14:08:44
Advertisements