
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Get table column names in alphabetical order in MySQL?
- Get all the column names in a table in MongoDB
- How to display the column names from a table excluding some in MySQL?
- How to can I get the names of my MySQL table columns?
- Get table names using SELECT statement in MySQL?
- How to get the primary key “column name” of a specific table in MySQL?
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- How to select all the column names from a table in Laravel?
- What is the SQL command to return the field names of a table?
- Get only the file extension from a column with file names as strings in MySQL?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Get the substring of a column in MySQL
- Setting column values as column names in the MySQL query result?
- How to get all the column names from a ResultSet using JDBC

Advertisements