我之前在oracle上写了一个触发器,如下:(是可以的,但移到mysql5.1上就不行了
create or replace trigger tg_sshs_companybill
after insert
on sshs_companybill
for each row
begin
update sshs_company set last_=:new.year_||'-'||:new.month_ where id_=:new.company_id_;
end tg_sshs_companybill;这个在oracle上是没问题的,可以移到mysql上就不行了,我想解决的问题是这样的:两张表 表1:person 
id:number,  --主键id 
unitid:number, --单位id,来源于表2中的主键 表2:unit 
id:number, --主键id 
countUser:number, --该单位共有多少人员 
lastjoindate:date --最后加入该单位的日期 我想在表person中插入一条记录的时候,自动更新表unit中记录, 
更新1,在统计该单位有多少人,或者原来的值+1, 
更新2,最后加入该单位的时间,(或者说是该单位最后使用的日期), 请大家帮帮忙,谢谢

解决方案 »

  1.   

    改成这样:create trigger tg_sshs_companybill 
    after insert 
    on sshs_companybill 
    for each row 
    begin 
    update sshs_company set last_=concat(new.year_,'-',new.month_) where id_=new.company_id_; 
    end; 
      

  2.   


    drop trigger tg_sshs_companybill if exists;
    delimiter //
    create or trigger tg_sshs_companybill 
    after insert 
    on sshs_companybill 
    for each row 
    begin 
    update sshs_company set last_= concat(new.year_,'-',new.month_ where id_=new.company_id_); 
    end;
    //