一、新建一个表
现在就可以创建触发器了,如图所示
1.删除(Delete)
(这是通过查询可创建的代码)下同
CREATE TRIGGER `test1` AFTER DELETE ON `baby` FOR EACH ROW
BEGIN
DELETE FROM score WHERE student_id = old.student_id;
END;
2.更新(Update)
CREATE TRIGGER `test2` AFTER UPDATE ON `baby` FOR EACH ROW BEGIN
UPDATE score SET student_id = new.student_id WHERE student_id = old.student_id;
END;
3.插入(Insert)
CREATE TRIGGER `test3` BEFORE INSERT ON `baby` FOR EACH ROW BEGIN
if new.student_age<16 THEN SET new.student_age =16;
END if;
END;
CREATE TRIGGER `test4` BEFORE INSERT ON `baby` FOR EACH ROW BEGIN
IF new.student_sex ='男' THEN SET new.student_sex = '男性';
END if ;
IF new.student_sex ='女' THEN SET new.student_sex = '女性';
END if;
END;