MySQL 数据库中生成数据字典方法的方法分享


摘要:
下文讲述MySQL数据库中,生成数据字典的方法分享,如下所示:


实现思路:
通过查询系统表 information_schema.COLUMNS 和 information_schema.Tables
获取相应的数据结构,如下所示:

SELECT
	a.TABLE_NAME AS '数据表名称',
	b.TABLE_COMMENT AS '数据表备注',
	a.COLUMN_NAME AS '列名',
	a.COLUMN_TYPE AS '列数据类型',
	a.IS_NULLABLE AS '是否可NULL',
IF
	( a.COLUMN_DEFAULT = '', '空字符串', IFNULL( a.COLUMN_DEFAULT, '无' ) ) AS '默认值',
	a.COLUMN_COMMENT AS '字段备注'
FROM
	information_schema.COLUMNS AS a
	JOIN information_schema.TABLES AS b ON a.TABLE_SCHEMA = b.TABLE_SCHEMA 
	AND a.TABLE_NAME = b.TABLE_NAME 
---WHERE
	---a.TABLE_SCHEMA = '数据表名称'