如何从 MySQL 中提取列名和类型?
若要提取列名和类型,请使用 INFORMATION_SCHEMA.COLUMNS −
select concat(column_name,'=',data_type) as anyAliasName from information_schema.columns where table_schema= yourDatabaseName and table_name= yourTableName;
我们先创建一个表 −
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)
以下是从 MySQL 中提取列名和类型的查询
mysql> select concat(column_name,'=',data_type) as COLUMNNAMEANDTYPE from information_schema.columns where table_schema= 'web' and table_name= 'DemoTable1812';
这将产生以下输出 −
+-------------------+ | COLUMNNAMEANDTYPE | +-------------------+ | Id=int | | FirstName=varchar | | Age=int | | isMarried=tinyint | | status=enum | +-------------------+ 5 rows in set (0.00 sec)
广告