IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    存储过程(2)

    天下发表于 2015-12-14 12:39:00
    love 0
    #1.修改my.conf
    # max_sp_recursion_depth = 16

    delimiter //
    CREATE TRIGGER doc_add AFTER INSERT ON doc_threads
    for each row begin
    update doc_forums set records=records+1 where fid=new.fid;
    call syncfid(new.fid,1);
    end;//
    delimiter ;


    delimiter //
    CREATE TRIGGER doc_move AFTER UPDATE ON doc_threads
    for each row begin
    IF old.fid != new.fid then
    update doc_forums set records=records+1 where fid=new.fid;
    update doc_forums set records=records-1 where fid=old.fid;
    call syncfid(new.fid,1);
    call syncfid(old.fid,-1);
    end IF;
    end;
    //
    delimiter ;


    delimiter //
    CREATE TRIGGER doc_del AFTER DELETE ON doc_threads
    for each row begin
    update doc_forums set records=records-1 where fid=old.fid;
    call syncfid(old.fid,-1);
    end;//
    delimiter ;


    delimiter //
    CREATE PROCEDURE `syncfid`(infid int,n int)
    BEGIN
        declare tmpfid int default 0;
        SELECT fup into tmpfid from doc_forums where fid=infid;
        if tmpfid THEN
            update doc_forums set records=records+(n) where fid=tmpfid;
            call syncfid(tmpfid,n);
        end if;
    END; //
    delimiter ;


    天下 2015-12-14 20:39 发表评论


沪ICP备19023445号-2号
友情链接