显示 MySQL 中表的所有字段?
mysqlmysqli database
要显示所有字段,请使用 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)