博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql生成数据字典
阅读量:4984 次
发布时间:2019-06-12

本文共 3845 字,大约阅读时间需要 12 分钟。

样式:

 

 

生成的存储过程:

DELIMITER $$USE `mtapp_toms`$$DROP PROCEDURE IF EXISTS `proc_getdatadic`$$CREATE DEFINER=`root`@`%` PROCEDURE `proc_getdatadic`()BEGINDECLARE v_tablename VARCHAR(50);DECLARE v_columnname VARCHAR(50);DECLARE v_disname VARCHAR(50);DECLARE v_priname VARCHAR(50);DECLARE v_datatype VARCHAR(50);DECLARE v_datalen VARCHAR(50);DECLARE v_desc VARCHAR(50);DECLARE v_col VARCHAR(255);DECLARE v_tname VARCHAR(50);DECLARE v_count INT;DECLARE done INT DEFAULT FALSE;DECLARE cur CURSOR FOR     SELECT * FROM (    SELECT     table_name 表名,    column_name 字段名,    column_name 显示名,    IF(column_key='PRI','是','') 主键,data_type 数据类型,    IF(character_maximum_length>0,character_maximum_length,'') 长度,    IF(column_comment='',column_name,column_comment) 说明      FROM information_schema.COLUMNS     WHERE TABLE_SCHEMA = 'mtapp_toms'    AND table_name LIKE 'tb_用户管理%'    AND table_name NOT LIKE '%_mm_%'    AND table_name NOT LIKE '%_dd_%'        AND table_name NOT LIKE '%19%'    AND table_name NOT LIKE '%18%'    UNION ALL    SELECT     table_name 表名,    column_name 字段名,    column_name 显示名,    IF(column_key='PRI','是','') 主键,data_type 数据类型,    IF(character_maximum_length>0,character_maximum_length,'') 长度,    IF(column_comment='',column_name,column_comment) 说明      FROM information_schema.COLUMNS     WHERE TABLE_SCHEMA = 'mtapp_toms'    AND (table_name LIKE 'tb_家宽%' OR table_name LIKE 'tb_集客%')    AND table_name NOT LIKE '%_mm_%'    AND table_name NOT LIKE '%_dd_%'    AND table_name NOT LIKE '%19%'    AND table_name NOT LIKE '%18%'    UNION ALL    SELECT     table_name 表名,    column_name 字段名,    column_name 显示名,    IF(column_key='PRI','是','') 主键,data_type 数据类型,    IF(character_maximum_length>0,character_maximum_length,'') 长度,    IF(column_comment='',column_name,column_comment) 说明      FROM information_schema.COLUMNS     WHERE TABLE_SCHEMA = 'mtapp_toms'    AND (table_name LIKE 'tb_退服%' OR table_name LIKE 'tb_动环%')    AND table_name NOT LIKE '%_mm_%'    AND table_name NOT LIKE '%_dd_%'    AND table_name NOT LIKE '%19%'    AND table_name NOT LIKE '%18%'    UNION ALL        SELECT     table_name 表名,    column_name 字段名,    column_name 显示名,    IF(column_key='PRI','是','') 主键,data_type 数据类型,    IF(character_maximum_length>0,character_maximum_length,'') 长度,    IF(column_comment='',column_name,column_comment) 说明      FROM information_schema.COLUMNS     WHERE TABLE_SCHEMA = 'mtapp_toms'    AND table_name  LIKE 'tb_%'     AND table_name  NOT LIKE 'tb_家宽%'     AND table_name  NOT LIKE 'tb_集客%'    AND table_name NOT LIKE 'tb_用户管理%'    AND table_name NOT LIKE 'tb_退服%'     AND table_name NOT LIKE 'tb_动环%'     AND table_name NOT LIKE '%_mm_%'    AND table_name NOT LIKE '%_dd_%'    AND table_name NOT LIKE '%19%'    AND table_name NOT LIKE '%18%') t;    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;DROP TEMPORARY TABLE IF EXISTS temp_dic;CREATE TEMPORARY TABLE temp_dic (col VARCHAR(255) NOT NULL);SET v_tname='';SET v_count=1;OPEN cur;read_loop: LOOPFETCH cur INTO v_tablename,v_columnname,v_disname,v_priname,v_datatype,v_datalen,v_desc;IF done THENLEAVE read_loop;END IF;IF(v_tablename!=v_tname) THEN    IF(v_count>1) THEN        INSERT INTO temp_dic VALUES('');    END IF;        INSERT INTO temp_dic VALUES(CONCAT('

',v_tablename,'

')); INSERT INTO temp_dic VALUES(CONCAT('
')); SET v_count=v_count+1;END IF;INSERT INTO temp_dic VALUES(CONCAT('
'));SET v_tname=v_tablename;END LOOP;CLOSE cur;IF(v_count>1) THEN INSERT INTO temp_dic VALUES('
字段名 显示名 主键 数据类型 长度 说明
',v_columnname,' ',v_disname,' ',v_priname,' ',v_datatype,' ',v_datalen,' ',v_desc,'
');END IF;SELECT * FROM temp_dic;END$$DELIMITER ;

 

转载于:https://www.cnblogs.com/ringwang/p/11164174.html

你可能感兴趣的文章
AES加密工具类[亲测可用]
查看>>
方法区
查看>>
Django-----ORM
查看>>
ARCGIS部分刷新
查看>>
发 零 食
查看>>
poj3613:Cow Relays(倍增优化+矩阵乘法floyd+快速幂)
查看>>
洛谷P1886 滑动窗口
查看>>
Shell编程(二)Bash中调用Python
查看>>
主动与被动监控 拓扑图组合图 自定义监控
查看>>
SQL总结(一)基本查询
查看>>
PDF分割--可脱离python环境执行,可传参数,可弹窗的PC端小工具
查看>>
cas-client-core单点登录排除不需要拦截的URL
查看>>
OCR技术浅探 : 文字定位和文本切割(2)
查看>>
jmeter集合点
查看>>
Java类代码块执行顺序
查看>>
克鲁斯卡尔(模板题)
查看>>
汉字转拼音
查看>>
Python中Web框架编写学习心得
查看>>
dataTable/dataSet转换成Json格式
查看>>
asp.net core模块学习
查看>>