温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql查询表字所有字段的方法

发布时间:2020-10-09 19:09:19 来源:亿速云 阅读:189 作者:小新 栏目:MySQL数据库

小编给大家分享一下mysql查询表字所有字段的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

mysql查询表字所有字段的方法:使用“SHOW FROM”语句配合FULL关键字来查询,语法“SHOW FULL COLUMNS FROM table_name”,可以显示指定数据表的所有字段信息。

mysql查询表字所有字段

1、查看所有表名:

show tables [from db_name];

2、查看字段信息

SHOW FULL COLUMNS FROM table_name

获取以下信息
Field :字段名
Type:字段类型
Collation:字符集(mysql 5.0以上有)
Null :是否可以为NULL
Key:索引(PRI,unique,index)
Default:缺省值
Extra:额外(是否 auto_increment)
Privileges:权限
Comment:备注(mysql 5.0以上有)

mysql> create table teacher  # 创建teacher表
    -> (
    -> Id int (5) auto_increment not null primary key,
    -> name char(10) not null,
    -> address varchar(50) default 'No.1 Mid school',
    -> year date
    -> );
Query OK, 0 rows affected (0.02 sec)

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| teacher          |
+------------------+
1 row in set (0.00 sec)

mysql> show full columns from teacher;  # 显示teacher表的所有字段
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
| Field   | Type        | Collation         | Null | Key | Default         | Extra          | Privileges                      | Comment |
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
| Id      | int(5)      | NULL              | NO   | PRI | NULL            | auto_increment | select,insert,update,references |         |
| name    | char(10)    | latin1_swedish_ci | NO   |     | NULL            |                | select,insert,update,references |         |
| address | varchar(50) | latin1_swedish_ci | YES  |     | No.1 Mid school |                | select,insert,update,references |         |
| year    | date        | NULL              | YES  |     | NULL            |                | select,insert,update,references |         |
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
4 rows in set (0.01 sec)

mysql> drop table teacher;  # 删除teacher表
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql>

看完了这篇文章,相信你对mysql查询表字所有字段的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI