当前位置:Gxlcms > mysql > 获取MySQL5.5表元信息

获取MySQL5.5表元信息

时间:2021-07-01 10:21:17 帮助过:28人阅读

最近,在写一个代码工具,从数据读取表生成实体Bean、SQLMap,需要获取到数据库的元信息,为了适应不同的数据库,需要针对每一种

SELECT t.column_name,
t.data_type,
CAST(SUBSTR(t.column_type, INSTR(t.column_type, '(') + 1, INSTR(t.column_type,')') - INSTR(t.column_type, '(') - 1) AS CHAR(20)) data_length,
CAST(t.column_type AS CHAR(20)) column_type,
t.column_comment,
IF (t.is_nullable='YES',1,0) is_nullable,
IF (t.column_key = 'PRI', 1, 0) is_key
FROM information_schema.columns t
WHERE t.table_schema = SCHEMA() AND
t.table_name = '表名'
ORDER BY t.ordinal_position;

人气教程排行