创建 MySQL 表时设置选项。同时显示相同的选项
若要显示,请使用 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)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP