January 2 2018

定时生产audit的表

delimiter $$
CREATE EVENT test_event
ON SCHEDULE EVERY 1 MONTH
STARTS ‘2018-01-01 00:00:00’
COMMENT ‘定时生产audit的表’
DO
BEGIN
set @cur_date=DATE_FORMAT(NOW(), ‘%Y%m’);
set @sqltext=concat(“rename table audit_trail to audit_trail_”, @cur_date,”;”);
PREPARE rename_table from @sqltext;
execute rename_table;
set @sqltext=concat(“create table audit_trail like audit_trail_”,@cur_date,”;”);
select @sqltext;
PREPARE c_table from @sqltext;
execute c_table;
END $$
delimiter ;



Copyright 2019. All rights reserved.

Posted 2018年1月2日 by ucjmh in category "mysql

Leave a Reply

Your email address will not be published. Required fields are marked *