 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 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
 