
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the name of a column in MySQL?
For this, you can use SHOW COLUMNS or INFORMATION_SCHEMA.COLUMN.
Let us first create a table −
mysql> create table DemoTable603 ( ClientId int NOT NULL AUTO_INCREMENT, ClientName varchar(100), ClientAge int, ClientAddress varchar(100), ClientCountryName varchar(100), ClientEducationDetails varchar(200), PRIMARY KEY(ClientId) ); Query OK, 0 rows affected (0.59 sec)
CASE 1 − Using SHOW command
Here is the query to find the name of a column in MySQL −
mysql> SHOW COLUMNS FROM DemoTable603;
This will produce the following output −
+------------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------+------+-----+---------+----------------+ | ClientId | int(11) | NO | PRI | NULL | auto_increment | | ClientName | varchar(100) | YES | | NULL | | | ClientAge | int(11) | YES | | NULL | | | ClientAddress | varchar(100) | YES | | NULL | | | ClientCountryName | varchar(100) | YES | | NULL | | | ClientEducationDetails | varchar(200) | YES | | NULL | | +------------------------+--------------+------+-----+---------+----------------+ 6 rows in set (0.00 sec)
CASE 2 − Using information_schema.column −
mysql> select column_name from information_schema.columns where table_schema='web' and table_name='DemoTable603';
This will produce the following output −
+------------------------+ | COLUMN_NAME | +------------------------+ | ClientAddress | | ClientAge | | ClientCountryName | | ClientEducationDetails | | ClientId | | ClientName | +------------------------+ 6 rows in set (0.00 sec)
- Related Questions & Answers
- How to find tables with a specific column name in MySQL?
- How to select a column name with spaces in MySQL?
- Given a column name how can I find which tables in a MySQL database contain that column?
- Rename column name in MySQL?
- How to select a column of a matrix by column name in R?
- How to get the primary key “column name” of a specific table in MySQL?
- MySQL query to display columns name first name, last name as full name in a single column?
- Fetch a specific column value (name) in MySQL
- How to find nth highest value of a MySQL column?
- How can I change the name of an existing column from a MySQL table?
- Wildcards in column name for MySQL?
- Display distinct column name in MySQL
- Change the column name from StudentName to FirstName in MySQL?
- How to extract column name and type from MySQL?
- How to find the name of the author of a package in R?
Advertisements