createtriggertrig_instercostcenterafterinsertoncost_centerforeachrowbegindeclare@codevarchar(20),@namevarchar(20);select@code=code,@name=namefromInserted;insertintooffice...
create trigger trig_instercostcenter
after insert on cost_center
for each row
begin
declare @code varchar(20), @name varchar(20);
select @code=code,@name=name from Inserted;
insert into office(office_code,office_name,cost_center_id,cost_center_code) values (@code,@name,'',@code);
end
是的,对mysql触发器不懂,后来修改成这样的了:
drop trigger if exists cost_center_office_trig;
create trigger cost_center_office_trig
after insert
on cost_center
for each row
begin
declare v_1 varchar(20);
declare v_2 varchar(20);
set v_1=(select code from cost_center where id=new.id);
set v_2=(select name from cost_center where id=new.id);
insert into office(office_code,office_name,cost_center_id,cost_center_code) values(v_1,v_2,"",v_2);
end
我的目的是当cost_center表插入数据时,office表也会插入相应数据,cost_center表有一个主键id,我执行
insert into cost_center(code,name,parent_code,is_root,is_sum_cost_center,is_for_profit,dist_level,groups,parent_name,has_children,cost_type_id)values('6666','王八蛋','','','','',0,'','','',null)时报错
Category Timestamp Duration Message Line Position
Error 2012-9-27 22:44:24 0:00:00.000 - MySQL Database Error: Incorrect integer value: '' for column 'cost_center_id' at row 1 17 0
展开