mysql触发器 日期判断

来源:互联网 发布:廖雪峰python pdf 编辑:程序博客网 时间:2024/06/08 12:19
--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;

0 0