最近,在写一个代码工具,从数据读取表生成实体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;