mysql获得表格的字段名称

mysql获得表格的字段名称,第1张

使用MYSQL的

desc

表名

语句可以获得此表的所有字段名称、类型和默认值设置

例如:desc

teacher

你可以当作其他SQL那样执行,试试就知道了。

SELECT

  table_name   AS  `表名`,

  table_type   AS  `类型`,

  engine       AS  `引擎`,

  VERSION AS `版本`,

  TABLE_COLLATION AS `字符集`

FROM

  information_schematables

WHERE

  table_schema = 'test'

ORDER BY

  table_name DESC;

+------------------+------------+--------+------+-------------------+

| 表名             | 类型       | 引擎   | 版本 | 字符集            |

+------------------+------------+--------+------+-------------------+

| test_sub_student | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_sub2        | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_sub         | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_rollup_1    | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_main_class  | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_main2       | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| test_main        | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| testuser         | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| td_testsalary    | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| sale_report      | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

| log_table        | BASE TABLE | InnoDB |   10 | latin1_swedish_ci |

+------------------+------------+--------+------+-------------------+

11 rows in set (000 sec)

在我第N次忘记如何查看表结构后,在网上查了一下后,看到有好几种查看表结构的方式,总结一下。

以student(sid,sname,birthday,sex)的查看为例。

方式一:desc student;

语法:desc 表名;---------------------用于查看表整体结构

方式二:describe student;

语法:describe 表名;---------------------用于查看表整体结构;

方式三:show columns from student;

语法:show columns from 表名;--------------------------用于查看表整体结构;

方式四:show create table student;

语法:show create table 表名;--------------------------用于查看表整体结构;

方式五:show full fields from student;

语法:show full fields from 表名;--------------------------------- 用于查看表整体结构;

方式六:show fields from student;

语法:show fields from 表名;----------------------------用于查看表整体结构;

方式七:desc student sname;

语法:desc 表名 成员名;--------------------------------用于查询表中的一部分;

方式八:show index from student;

语法:show index from 表名;------------------------------------用于查看表局部结构;这种显示不是很直观,也不是可以完全显示所有信息。

MySQL 查看表结构简单命令。

一、简单描述表结构,字段类型desc tabl_name;

显示表结构,字段类型,主键,是否为空等属性,但不显示外键。

二、查询表中列的注释信息

select from information_schemacolumns where table_schema = 'db' #表所在数据库

1、开启电脑,并打开mysql的数据库,在数据库中点击并进入右上的查询,在点击查询下面的新建查询。如图,

2、接下来就可以输入SELECT from crew_1 order by gmt_create这个语句,然后表中的所有记录就会按时间排序查询。如图。

3、如果需要获取表中按时间排序的第一条记录,就输入SELECT from crew_1 order by gmt_create desc limit 0,1,如图

4、如果需要获取第5条记录,就输入SELECT from crew_1 order by gmt_create desc limit 4,1如图:

5、如果需要获取第1001条记录,只需要将limit 4,1改成limit 1000,1,如果需要获取第n条记录,查询语句加入limit n-1,1就可以了,如图:

6、如果需要获取表中前n条记录,改成limit n,如图;

以上就是关于mysql获得表格的字段名称全部的内容,包括:mysql获得表格的字段名称、mysql 如何获取数据库下所有的表、mysql怎么查看表结构等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9514089.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存