查询表的字段:
-- 查询表的字段名 SELECT COLUMN_NAME -- GROUP_CONCAT('a.', COLUMN_NAME SEPARATOR ',') AS COLUMN_NAME -- 加表别名并用逗号连接 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'hera' -- 数据库名 AND TABLE_NAME = 'tbn_car' -- 表名 ;
查询表结构:
-- 查询表结构 SELECT TABLE_NAME AS '表名', COLUMN_NAME AS '字段名', COLUMN_TYPE AS '类型', COLUMN_KEY AS '主键', COLUMN_COMMENT AS '说明' FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'hera' -- 数据库名 AND TABLE_NAME = 'tbn_car' -- 表名 ;
.