当前位置:Gxlcms > mysql > MySQL定时创建表的SQL语句_MySQL

MySQL定时创建表的SQL语句_MySQL

时间:2021-07-01 10:21:17 帮助过:2人阅读

bitsCN.com
MySQL定时创建表的SQL语句 -- 查看事件计划SELECT @@event_scheduler -- 打开事件计划 SET GLOBAL event_scheduler = 1 -- 存储过程,每月创建一张表CREATE PROCEDURE create_table()BEGIN declare str_date varchar(16);SET str_date = date_format(now(),"%Y%m"); SET @sqlcmd1 = CONCAT('CREATE TABLE db_mail_message_',str_date,"(apptaskid varchar(100) NOT NULL,taskname varchar(200) NOT NULL,appsenduid varchar(200) NOT NULL,appreceiveuid varchar(100) NOT NULL,sendtime varchar(50) NOT NULL,handletime varchar(50) NOT NULL,url varchar(500) NOT NULL,remark varchar(500) NOT NULL,endtime varchar(50) NOT NULL,imapuid varchar(100) NOT NULL,addstatus int(1) NOT NULL DEFAULT '0',readstatus int(1) NOT NULL DEFAULT '0',deletestatus int(1) NOT NULL DEFAULT '0',completestatus int(1) NOT NULL DEFAULT '0',PRIMARY KEY (apptaskid),KEY db_imapuid_index (imapuid)) ENGINE=MyISAM DEFAULT CHARSET=utf8;");PREPARE p1 FROM @sqlcmd1;EXECUTE p1;DEALLOCATE PREPARE p1;END-- 创建事件:每隔一秒自动调用存储过程CREATE EVENT IF NOT EXISTS e_testON SCHEDULE EVERY 1 SECONDON COMPLETION PRESERVEDO CALL test(); -- 创建事件:每月1号1点自动调用存储过程(未测试)CREATE EVENT if not exists e_test on schedule every 1 MONTH STARTS DATE_ADD(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY), INTERVAL 1 MONTH),INTERVAL 1 HOUR) on completion preserve do call test();-- 开启事件alter event e_test ON COMPLETION PRESERVE ENABLE;-- 关闭事件alter event e_test ON COMPLETION PRESERVE DISABLE; bitsCN.com

人气教程排行