众所周知,DESCRIBE 语句将提供整个表的信息/结构。借助 DESCRIBE 语句以及表名和列名,我们可以获得有关该列的信息。
语法DESCRIBE table_name col_name;
示例1
mysql> Describe employee ID;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
1 row in set (0.11 sec)
DESCRIBE table_name col_name;
mysql> Describe employee ID;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
1 row in set (0.11 sec)
上面的查询将提供有关名为“employee”的表的“ID”列的信息。
示例2< /h2>mysql> Describe employee name;
+-------+-------------+------+-----+---------+---------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+---------+
| Name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+---------+
1 row in set (0.03 sec)
mysql> Describe employee name;
+-------+-------------+------+-----+---------+---------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+---------+
| Name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+---------+
1 row in set (0.03 sec)
上面的查询将提供有关名为“employee”的表的另一列“Name”的信息。