在 MySQL 中显示表格的所有字段?


要显示所有字段,请使用以下语法将数据库设置为 table_schema,将特定表设置为 table_name −

select column_name as anyAliasName from information_schema.columns
   where table_schema=database()
   and table_name=’yourTableName’\G

我们先创建一个表 −

mysql> create table DemoTable1938
   (
   StudentId int,
   StudentName varchar(20),
   StudentAge int,
   StudentCountryName varchar(20),
   StudentMobileNumber bigint
   );
Query OK, 0 rows affected (0.00 sec)

以下是显示表中所有字段的查询 −

mysql> select column_name as ALL_FIELDS from information_schema.columns
   where table_schema=database()
   and table_name='DemoTable1938'\G

这将产生以下输出 −

*************************** 1. row ***************************
ALL_FIELDS: StudentId
*************************** 2. row ***************************
ALL_FIELDS: StudentName
*************************** 3. row ***************************
ALL_FIELDS: StudentAge
*************************** 4. row ***************************
ALL_FIELDS: StudentCountryName
*************************** 5. row ***************************
ALL_FIELDS: StudentMobileNumber
5 rows in set (0.00 sec)

更新于: 30-Dec-2019

1K+ 浏览

开启你的 职业

通过完成课程获得认证

开始
广告