=================================
mysql5.0.22
=================================
--1、创建表
--2、插入模拟数据
--3、创建触发器
--4、测试
--说明:当向表tab1中插入数据时,修改tab2中相应列的值;
-----
mysql5.0.22
=================================
--1、创建表
create table tab1(t1_id varchar(15),v1 varchar(15));
create table tab2(t2_id varchar(15),v2 varchar(15));
--2、插入模拟数据
insert into tab1 values('001','100');
insert into tab2 values('001','123');
--3、创建触发器
create trigger t_afterinsert_on_tab1
after insert on tab1
for each row
begin
update tab2 set v2=new.v1+v2 where new.t1_id=t2_id;
end;
--4、测试
insert into tab1 values('001','111');
--说明:当向表tab1中插入数据时,修改tab2中相应列的值;
-----
create trigger t_afterinsert_on_tab1 after insert on tab1 for each row begin update tab2
set v2=new.v1+v2 where new.t1_id=t2_id; end;