mysql触发器是非常重要的概念,下面为您介绍的是mysql触发器的三个状态,供您参考,希望让您对mysql触发器能够有更深的认识。
- CREATE
- TRIGGER `user1_user2` AFTER INSERT ON `user1`
- FOR EACH ROW insert into user2 SELECT * from user1 order by id desc limit 1
- WHERE id>=LAST_INSERT_ID()
- AND id <=LAST_INSERT_ID()+ROW_COUNT()
- CREATE
- TRIGGER `update_user` AFTER UPDATE ON `user1`
- FOR EACH ROW update user2 set name=new.user,info=new.pwd where id=old.id;
- CREATE
- TRIGGER `del_user` AFTER DELETE ON `user1`
- FOR EACH ROW delete from user2 where id=old.id
- =================复杂的insert
- CREATE TRIGGER `test`.`insert_user2` AFTER INSERT ON `test`.`user1`
- FOR EACH ROW INSERT INTO user2
- SET `id` = NEW.id,
- `name` = NEW.user,
- `info` = NEW.pwd,
- `date2` = UNIX_TIMESTAMP( NEW.date1 ) ,
- `enum2` = NEW.enum1 -1,
- `aid`=(select aid from protype where id=NEW.type_id)
以上mysql触发器的三个状态介绍。
【编辑推荐】