- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What is the SQL command to return the field names of a table?
To return the field names of a table, you can use desc command. The syntax is as follows −
desc yourTableName;
Or you can use column_name field from information_schema.columns table. The syntax is as follows −
select column_name from information_schema.columns where table_name = ’yourTableName’;
To understand both the syntax, let’s say we have a table ‘ExtractCommentDemo1’.
Using the first syntax −
mysql> desc ExtractCommentDemo1;
The following is the output displaying the fields −
+----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | UserId | int(11) | YES | | NULL | | | UserName | varchar(200) | YES | | NULL | | +----------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
Using the second syntax:
mysql> select column_name from INFORMATION_SCHEMA.COLUMNS −> where table_name = 'ExtractCommentDemo1';
The following is the output displaying the field names −
+-------------+ | COLUMN_NAME | +-------------+ | UserId | | UserName | +-------------+ 2 rows in set (0.00 sec)
- Related Articles
- What is the use of update command in SQL?
- MySQL Quoted table/field names vs unquoted names?
- What is the syntax in MySQL to get the column names of a table?
- Check if a field of table has NOT NULL property set in SQL?
- Viewing field names or tables names of the forms in SAP Business One
- What is MySQL UNIQUE constraint and how can we apply it to the field of a table?
- What is the purpose of the command interpreter?
- Show MySQL host via SQL Command?
- MongoDB aggregate to get the count of field values of corresponding duplicate names?
- MongoDB query to get specific list of names from documents where the value of a field is an array
- How to know if MySQL binary log is enabled through SQL command?
- What is the use of IGNORE_SPACE SQL mode?
- What is the use of ALLOW_INVALID_DATES SQL mode?
- MySQL command to copy table?
- How to select all the column names from a table in Laravel?

Advertisements