Display all fields of a table in MySQL?


To display all fields, set the database with table_schema and specific table with table_name as in the below syntax −

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

Let us first create a table −

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

Here is the query to display all fields of a table −

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

This will produce the following output −

*************************** 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)

Updated on: 30-Dec-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements