MYSQL 存储过程与计划任务结合使用

使用计划任务让数据库在某个时间自动执行一个存储过程

存储过程
        delimiter //
        create procedure integral_back(IN order_id INTEGER)
        BEGIN
            declare order_uid int;
            declare order_total DECIMAL(8,2);
        
            select uid, total into order_uid, order_total from shop_orders where id = order_id;
            update user set integral = integral + order_total where id = order_uid;
        END
        //
    
MYSQL计划任务, 在某个时间点执行一个存储过程
        drop event if exists integral_back;
        create event integral_back

                on schedule at '2018-11-22 15:06:30'

                do call integral_back(1);
        

猜你喜欢

转载自blog.csdn.net/d429667292/article/details/84562191