Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to can I get the names of my MySQL table columns?
You can use SHOW command for this.
Following is the syntax −
show columns from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20), StudentLastName varchar(20), StudentAge int, StudentAddress varchar(200) ); Query OK, 0 rows affected (0.54 sec)
Following is the query to get the names of my MySQL table columns −
mysql> show columns from DemoTable;
This will produce the following output −
+------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentFirstName | varchar(20) | YES | | NULL | | | StudentLastName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentAddress | varchar(200) | YES | | NULL | | +------------------+--------------+------+-----+---------+----------------+ 5 rows in set (0.01 sec)
Advertisements
