创建 MySQL 表时设置选项。同时显示相同的选项

mysqlmysqli database更新于 2025/12/8 21:00:17

要显示,请使用 DESC 命令或 information_schema.columns。让我们先创建一个表并设置选项 −

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

案例 1

以下是使用 DESC 命令获取 SET 可用选项列表的查询 −

mysql> desc DemoTable;

这将产生以下输出 −

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

案例 2

这是使用 information_schema.columns 概念查询 SET 可用选项列表 −

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

这将产生以下输出 −

+------------------------------------+
| COLUMN_TYPE                        |
+------------------------------------+
| set('RED','GREEN','BLUE','YELLOW') |
+------------------------------------+
1 row in set (0.01 sec)

相关文章


有用资源