您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

返回表的字段名称的 SQL 命令是什么?

2025/11/22 6:14:55发布51次查看
要返回表的字段名称,可以使用 desc 命令。语法如下 -
desc yourtablename;
或者您可以使用 information_schema.columns 表中的 column_name 字段。语法如下 -
select column_name from information_schema.columns where table_name = ’yourtablename’;
为了理解这两种语法,假设我们有一个表“extractcommentdemo1”。
使用第一种语法 -
mysql> desc extractcommentdemo1;
以下是显示字段的输出 -
+----------+--------------+------+-----+---------+-------+| field | type | null | key | default | extra |+----------+--------------+------+-----+---------+-------+| userid | int(11) | yes | | null | || username | varchar(200) | yes | | null | |+----------+--------------+------+-----+---------+-------+2 rows in set (0.00 sec)
使用第二种语法:
mysql> select column_name from information_schema.columns −> where table_name = 'extractcommentdemo1';
以下是显示字段名称的输出 -
+-------------+| column_name |+-------------+| userid || username |+-------------+2 rows in set (0.00 sec)
以上就是返回表的字段名称的 sql 命令是什么?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product