在更新触发器中声明变量

时间:2015-05-26 09:15:07

标签: mysql triggers

我有一张projects表。我希望在statusupdate表中进行任何修改时更新projects表。

statusupdate表中最多有20个程序代码。这是我到目前为止工作的触发器,但它显示#error没有别的

DELIMITER $$
    CREATE TRIGGER statuss AFTER INSERT,Update ON projects
    FOR EACH ROW 
    begin
        DECLARE ongoing int default 0;
        DECLARE completed int default 0;
        DECLARE pending int default 0;
        Set @ongoing =(select count(ProjStatus) from projects where ProjStatus='Ongoing'); 
        Set @completed =(select count(ProjStatus) from projects where ProjStatus='Completed'); 
        Set @pending =(select count(ProjStatus) from projects where ProjStatus='Pending'); 
        update statusupdate 
        (Prov ,Ongoing,Completed,Pending )
        values 
        (OLD.ProvId,@ongoing,@completed,@pending)
        where ProgCode=OLD.ProgramCode
    end $$ 
DELIMITER ;

0 个答案:

没有答案