博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 获取数据库表、字段存储过程
阅读量:6389 次
发布时间:2019-06-23

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

hot3.png

 

DELIMITER $$DROP PROCEDURE IF EXISTS `paltform`.`pt_init` $$CREATE PROCEDURE `platform`.`pt_init` ()BEGIN/* Clear the table TablesRemark which the table has being delete from sys tables */DELETE FROM tablesremark  WHERE tablename NOT IN (    SELECT t.table_name AS tablename      FROM information_schema.tables t      WHERE t.table_schema = 'paltform');/* Check the sys tables,add the tables   which does exist in the sys tables   but does not exist in the table TablesRemark */INSERT INTO tablesremark(tablename)  SELECT LCASE(t.table_name) AS tablename    FROM information_schema.tables t      WHERE t.table_schema = 'platform'    AND t.table_name NOT IN (SELECT tablename FROM tablesremark);/* Clear the table ColsRemark which the table_column has being delete from the sys tables,columns */CREATE TEMPORARY TABLE temp  SELECT CONCAT(CONCAT(LCASE(t.table_name) ,'_'), LCASE(c.column_name)) AS tablecolname    FROM information_schema.tables t    INNER JOIN information_schema.columns c          ON t.table_name = c.table_name          WHERE t.table_schema = 'platform';DELETE FROM colsremark WHERE id not IN (SELECT tablecolname FROM temp);DROP TABLE temp;/* Add the table_column data into the table ColsRemark   which does exist in the sys tables,columns   but does not exist in the table ColsRemark */INSERT INTO ColsRemark (id , tablename, colname, colorder, addtime)  SELECT CONCAT(CONCAT(LCASE(t.table_name) ,'_'), LCASE(c.column_name)) AS id,         LCASE(t.table_name) AS tablename,         LCASE(c.column_name) AS colname,         c.ordinal_position AS colorder,         now() AS addtime    FROM information_schema.tables t    INNER JOIN information_schema.columns c          ON t.table_name = c.table_name          WHERE t.table_schema = 'platform'          AND (            NOT EXISTS                (SELECT id FROM colsremark col                  WHERE col.tablename = t.table_name and col.colname = c.column_name                )          );/* Update the table TablesRemark's column colchanged   if the col has be changed in the table ColsRemark */UPDATE tablesremark SET colchanged = 1  WHERE tablename IN (SELECT tablename FROM colsremark WHERE colchanged=1);/* Update the table ColsRemark's column colorder   so that the order can as the same as the sys columns   optimized sql */UPDATE colsremark,( SELECT c.column_name,t.table_name,c.ordinal_position 	FROM information_schema.columns c,information_schema.tables t 	WHERE c.table_name=t.table_name) temp 	SET colsremark.colorder=temp.ordinal_position 	WHERE temp.column_name=colsremark.colname;/* not optimized sqlUPDATE colsremark SET colorder =  (SELECT c.ordinal_position    FROM information_schema.columns c    INNER JOIN information_schema.tables t    ON c.table_name=t.table_name    WHERE c.column_name=colsremark.colname    AND t.table_name=colsremark.tablename);*/UPDATE colsremark SET categoryid = '{612F4576-4BF6-424A-BB92-04E836CAB4FF}' WHERE colname IN ('adder' , 'moder');UPDATE colsremark SET categoryid = '{0ECC56D4-9F55-4633-8A41-172CB220ABF9}' WHERE colname IN ('delstatus');UPDATE colsremark SET categoryid = '{57460F9A-7F41-4733-84F5-AB1DDEAFBB0F}' WHERE colname IN ('rdeptid');END $$DELIMITER ;

转载于:https://my.oschina.net/darkness/blog/510260

你可能感兴趣的文章
keepalived详解 结合lvs
查看>>
../include/my_global.h:1107: 错误:对 C++ 内建类型‘bool’的重声明
查看>>
使用Spring MVC 4构建Restful服务
查看>>
Cocos2dx小技巧 单例
查看>>
php使用memcache存储session
查看>>
js iframe是否加载完成,加载完成执行函数
查看>>
Python基础知识(五)--数据类型
查看>>
面经-智力题
查看>>
二十四,Arrays和比较器
查看>>
解决Docker容器 iptables问题
查看>>
如何在CentOS6.2上安装并运行飞鸽传书
查看>>
ssh登陆问题
查看>>
Mysql执行计划
查看>>
Android布局之LinearLayout
查看>>
veeam.Backup.and.Replication 6 测试之二--backup和replication功能
查看>>
fedora 17 安装极点五笔
查看>>
OpenCV3的机器学习算法-K-means-使用Python
查看>>
我的友情链接
查看>>
英特尔分布式深度学习平台Nauta-安装、配置与管理指南
查看>>
Microsoft 用户体验虚拟化 UE-V 1.0 RC 发布
查看>>