背景:
触发器的定义
delimiter //
create trigger trigger_name vent_time event on table_name
for each row
begin
# code --------------
# code --------------
end
//
delimiter ;
使用 new.columname
old.columname 对行进行引用。
---------------------------------------------------------------------------------------------------------------------------------------------------
例子:
create table T1(X varchar(32) not null,Y varchar(32));
create table T2(tableName varchar(32) not null,tableEvent varchar(32));
------------------------------------------------------------------------
delimiter //
create trigger trigger_for_T1_insert before insert on T1
# 当T1表要插入数据时,要把这个事件记录到T2表
for each row
begin
insert into T2(tableName,tableEvent) values('T1','insert');
end //
delimiter ;
--------------
insert into T1(X,Y) values('XX','YY');
--------------
select * from T2;