建立 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)
廣告