码迷,mamicode.com
首页 > 数据库 > 详细

mysql 使用存储过程,事件等的一些小笔记 [Mark]

时间:2014-12-19 14:12:36      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

------------------------------------------------------------------------------------------------
[创建存储过程,使用变量,随机数字]

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;

mysql 使用存储过程,事件等的一些小笔记 [Mark]

标签:

原文地址:http://www.cnblogs.com/xjon/p/4173656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!