如何在一个预定事件中获得多个MySQL语句?

时间:2012-07-10 11:03:08

标签: mysql

我试图在一个预定的事件中做两个语句,但它不起作用。它什么都不做。你能帮我弄清楚出了什么问题吗?

delimiter |
CREATE EVENT resetTimeClockTimeToday 
ON SCHEDULE EVERY 1 DAY STARTS '2012-07-10 00:00:00' DO 
BEGIN 
   UPDATE timeclock.employees SET timeToday = 0; 
   UPDATE timeclock.punches SET missedOut = 1 WHERE timeOUT IS NULL; 
END|
delimiter ;

2 个答案:

答案 0 :(得分:-1)

您需要正确使用不同的分隔符,例如:

DROP EVENT IF EXISTS `Daily Event`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` EVENT `Daily event` ON SCHEDULE EVERY 1 DAY STARTS '2015-03-06 00:30:00' ON COMPLETION PRESERVE ENABLE DO
BEGIN

-- Newly due summary sheets
UPDATE          `summaries`
SET             `status` = 'DUE'
WHERE           `status` = 'OPEN'
AND             NOW() >= LAST_DAY(CONCAT(`year`, '-', `month`, '-01'));

-- Alert user that didn't clock out
INSERT INTO     `alerts` (`from`, `to`, `subject`, `message`)
SELECT          ....;

-- Alert manager that didn't clock out
INSERT INTO     `alerts` (`from`, `to`, `subject`, `message`)
SELECT          ....;

-- Alert for stale tickets
INSERT INTO     `alerts` (`from`, `to`, `subject`, `message`)
SELECT          ....;

END;
$$;

答案 1 :(得分:-4)

我重新启动了MySQL服务,它运行良好!