diff --git a/2208/天天乐学考试答案/MySQL练习(一).md b/2208/天天乐学考试答案/MySQL练习(一).md index 8641bc4..ba84b72 100644 --- a/2208/天天乐学考试答案/MySQL练习(一).md +++ b/2208/天天乐学考试答案/MySQL练习(一).md @@ -60,6 +60,24 @@ WHERE money >= 5000 AND money <= 8000; #6 +#9 触发器 +DELIMITER $$ +DROP TRIGGER IF EXISTS tri_updateGroup; +CREATE TRIGGER tri_updateGroup +BEFORE UPDATE ON t_employee +FOR EACH ROW +BEGIN + IF NEW.age != OLD.age THEN + IF NEW.age<30 THEN + SET NEW.groups = '青年'; + ELSEIF NEW.age<50 THEN + SET NEW.groups = '中年'; + ELSE + SET NEW.groups = '老年'; + END IF; + END IF; +END $$ +DELIMITER ; #10 存储过程 DELIMITER $$ #改变代码结束符