------------------------------------------------------------------------------------------------
[創建存儲過程,使用變量,隨機數字]
DELIMITER $$
DROP PROCEDURE IF EXISTS `week_luck_call` $$
CREATE PROCEDURE week_luck_call()
begin
DECLARE var_rankluck INT DEFAULT 99999; -- 必須放在第一行
delete from rankluck;
set var_rankluck = ROUND(ROUND(RAND(),5)*100000);
insert into rankluck (`guid`, `luck`) select `guid`, var_rankluck from ranklist order by value desc limit 100;
end $$
DELIMITER ;
------------------------------------------------------------------------------------------------
[創建mysql事件,事件觸發時間、周期等]
delimiter $$
create procedure week_luck_call()
begin
delete from rankluck;
insert into rankluck (`guid`, `luck`) select `guid`, ROUND(ROUND(RAND(),5)*100000) from ranklist order by value desc limit 100;
end $$
delimiter ;
drop procedure week_luck_call;
create event week_luck on schedule every 1 week starts '2014-12-17 08:00:00' on completion preserve do call week_luck_call();
drop event week_luck;