mysql查看表结构的两种方法
1、使用的就是desc 表名查看表结构,缺点是输出的信息还不够全面。
-- desc查看表结构,也可以使用describe,desc是descride的简写,效果相同mysql> desc info;
+-------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | enum('male','female') | YES | | NULL | |
| phone | bigint(11) | YES | | NULL | |
+-------+-----------------------+------+-----+---------+-------+
5 rows in set (0.94 sec)
mysql> describe info;
+-------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | enum('male','female') | YES | | NULL | |
| phone | bigint(11) | YES | | NULL | |
+-------+-----------------------+------+-----+---------+-------+
5 rows in set (0.08 sec)
2、使用show create table语法。除了可以看到表定义之外,还可以看到engine和charset等信息。
-- desc查看表结构,也可以使用describe,desc是descride的简写,效果相同mysql> desc info;
+-------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | enum('male','female') | YES | | NULL | |
| phone | bigint(11) | YES | | NULL | |
+-------+-----------------------+------+-----+---------+-------+
5 rows in set (0.94 sec)
mysql> describe info;
+-------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | enum('male','female') | YES | | NULL | |
| phone | bigint(11) | YES | | NULL | |
+-------+-----------------------+------+-----+---------+-------+
5 rows in set (0.08 sec)
以上就是mysql查看表结构的两种方法,希望对大家有所帮助。更多mysql学习指路:MySQL
推荐操作系统:windows7系统、mysql5.8、DELL G3电脑
以上是 mysql查看表结构的两种方法 的全部内容, 来源链接: utcz.com/z/545152.html