Mysql 导出视图、触发器

一:导出视图

SELECT CONCAT("DROP VIEW IF EXISTS `",TABLE_SCHEMA,"`.`",TABLE_NAME,"`;\nCREATE VIEW `", TABLE_SCHEMA,"`.`",TABLE_NAME,"` as ",VIEW_DEFINITION,";") 
FROM   information_schema.VIEWS  
where  TABLE_SCHEMA like  '%XXX%' ;

 

二:导出触发器

SELECT CONCAT("DROP TRIGGER IF EXISTS `",TRIGGER_SCHEMA, "`.`", TRIGGER_NAME,"`;\nDELIMITER ;;\nCREATE TRIGGER `",TRIGGER_SCHEMA,"`.`",
TRIGGER_NAME,"` ",ACTION_TIMING," ",EVENT_MANIPULATION," ON 
`",EVENT_OBJECT_SCHEMA,"`.`",EVENT_OBJECT_TABLE,"` FOR EACH ROW\n",ACTION_STATEMENT,";;\nDELIMITER ;")  FROM information_schema.TRIGGERS;

  

posted @ 2021-09-02 17:35  唏嘘-  阅读(866)  评论(0编辑  收藏  举报