1.变量提示
NEW 是新值-- OLD 是旧值
INSERT 只有NEW ----UPDATE有NEW和OLD ---DELETE只有OLD
2.准备测试表(userinfo、userinfolog)
use test;
create table userinfo(userid int,username varchar(10),userbirthday date);
create table userinfolog(logtime datetime,loginfo varchar(100));
describe userinfo;
3.建立同时插入两张表的触发器beforeinsertuserinfo
# 定义触发器
delimiter $$
create trigger beforeinsertuserinfo
before insert on userinfo
for each row begin
insert into userinfolog values(now(),CONCAT(new.userid,new.username));
end;
$$
delimiter ;
show triggers;
4.建立插入数据存储过程spinsertuserinfo
# 存储过程定义
delimiter $$
create procedure spinsertuserinfo(puserid int,pusername varchar(10),puserbirthday date)
begin
insert into userinfo values(puserid,pusername,puserbirthday);
end;
$$