mysql触发器 日期判断

--test1表
create table test1(
col datetime
);


--test1表的测试数据

INSERT INTO test1 VALUES ('20150101010101');


--test2表
create table test2(
col1 datetime,
name varchar(20)
);

--test2表的测试数据
INSERT INTO test2 VALUES ('20160301010203', 'zhangsan');
INSERT INTO test2 VALUES ('20160302010203', 'zhangsan');


--触发器,
delimiter //
 CREATE TRIGGER tg1 AFTER INSERT ON test2
 FOR EACH ROW
 BEGIN
DECLARE testtime datetime;
select col into testtime from test1;
IF testtime < NEW.col1 THEN
update test1 set col=NEW.col1; 
END IF;
 END;//
 delimiter ;


drop trigger tg1;

你可能感兴趣的:(触发器,mysql)