- 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
What is the syntax in MySQL to get the column names of a table?
The syntax is as follows to get the column names of a table −
select column_name from information_schema.columns where table_schema='yourDatabaseName' and table_name=’yourTableName’;
Let us first create a table −
mysql> create table DemoTable ( EmployeeId int, EmployeeFirstName varchar(20), EmployeeLastName varchar(20), EmployeeAge int, EmployeeCountryName varchar(40), IsMarried tinyint(1), isActive ENUM('ACTIVE','INACTIVE') ); Query OK, 0 rows affected (0.65 sec)
Following is the query to get the column names of a table. Here, we are fetching the column names of DemoTable −
mysql> select column_name from information_schema.columns where table_schema='web' and table_name='DemoTable';
This will produce the following output −
+---------------------+ | COLUMN_NAME | +---------------------+ | EmployeeId | | EmployeeFirstName | | EmployeeLastName | | EmployeeAge | | EmployeeCountryName | | IsMarried | | isActive | +---------------------+ 7 rows in set (0.00 sec)
Advertisements