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 extract column name and type from MySQL?
To extract column name and type, use INFORMATION_SCHEMA.COLUMNS −
select concat(column_name,'=',data_type) as anyAliasName from information_schema.columns where table_schema= yourDatabaseName and table_name= yourTableName;
Let us first create a table −
mysql> create table DemoTable1812
(
Id int,
FirstName varchar(20),
Age int,
isMarried boolean,
status ENUM('ACTIVE','INACTIVE')
);
Query OK, 0 rows affected (0.00 sec)
Here is the query to extract column name and type from MySQL:
mysql> select concat(column_name,'=',data_type) as COLUMNNAMEANDTYPE from information_schema.columns where table_schema= 'web' and table_name= 'DemoTable1812';
This will produce the following output −
+-------------------+ | COLUMNNAMEANDTYPE | +-------------------+ | Id=int | | FirstName=varchar | | Age=int | | isMarried=tinyint | | status=enum | +-------------------+ 5 rows in set (0.00 sec)
Advertisements
