- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements